onChildClick没有打开活动

时间:2014-11-20 14:25:34

标签: android expandablelistview

大家早上好。 onChildClick侦听器未打开新活动。尝试使用开关,现在是一个if语句,仍然没有运气。我确实将活动添加到清单中,但仍然没有运气。谢谢你的帮助。

活动

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;

public class ExpActivity extends FragmentActivity {

    ExpandableListView lv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.expandable_main);
        lv = (ExpandableListView) findViewById(R.id.expListView);

        lv.setOnChildClickListener(new OnChildClickListener() {

            @Override
            public boolean onChildClick(ExpandableListView parent, View v,
                    int groupPosition, int childPosition, long id) {
                if (groupPosition == 0 && childPosition == 0) {
                    Intent a1 = new Intent(ExpActivity.this, A380SeatingChartActivity.class);
                    startActivity(a1);
                    Log.e("MY TAG", "child clicked");
                }
                return true;
            }
        });
    }
}

新活动

import android.app.Activity;
import android.os.Bundle;

public class A380SeatingChartActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.airbus_seating_chart);
    }
}

XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center|center_vertical"
        android:src="@drawable/a318_seating_chart" />

</LinearLayout>

logcat的

11-20 11:27:02.782: I/ActivityManager(1265): Displayed com.example.ala/.Splash: +1s213ms
11-20 11:27:03.122: I/ActivityManager(1265): START u0 {act=com.example.ala.MAINACTIVITY cmp=com.example.ala/.MainActivity} from pid 1860
11-20 11:27:03.232: D/dalvikvm(1860): GC_FOR_ALLOC freed 14K, 3% free 8163K/8364K, paused 3ms, total 5ms
11-20 11:27:03.232: I/dalvikvm-heap(1860): Grow heap (frag case) to 10.125MB for 2073612-byte allocation
11-20 11:27:03.242: D/dalvikvm(1860): GC_FOR_ALLOC freed 3K, 3% free 10184K/10392K, paused 2ms, total 2ms
11-20 11:27:03.282: D/android.widget.GridLayout(1860): horizontal constraints: x1-x0>=174, x2-x1>=174, x3-x2>=174, x3-x0<=480 are inconsistent; permanently removing: x3-x0<=480. 
11-20 11:27:03.332: W/EGL_emulation(1860): eglSurfaceAttrib not implemented
11-20 11:27:03.932: I/ActivityManager(1265): Displayed com.example.ala/.MainActivity: +809ms
11-20 11:27:36.473: I/ActivityManager(1265): START u0 {cmp=com.example.ala/.AircraftActivity} from pid 1860
11-20 11:27:36.483: E/SoundPool(1265): error loading /system/media/audio/ui/Effect_Tick.ogg
11-20 11:27:36.483: W/AudioService(1265): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
11-20 11:27:36.483: E/SoundPool(1265): error loading /system/media/audio/ui/Effect_Tick.ogg
11-20 11:27:36.483: W/AudioService(1265): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
11-20 11:27:36.483: E/SoundPool(1265): error loading /system/media/audio/ui/Effect_Tick.ogg
11-20 11:27:36.483: W/AudioService(1265): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
11-20 11:27:36.483: E/SoundPool(1265): error loading /system/media/audio/ui/Effect_Tick.ogg
11-20 11:27:36.483: W/AudioService(1265): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
11-20 11:27:36.483: E/SoundPool(1265): error loading /system/media/audio/ui/Effect_Tick.ogg
11-20 11:27:36.483: W/AudioService(1265): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
11-20 11:27:36.483: E/SoundPool(1265): error loading /system/media/audio/ui/KeypressStandard.ogg
11-20 11:27:36.483: W/AudioService(1265): Soundpool could not load file: /system/media/audio/ui/KeypressStandard.ogg
11-20 11:27:36.483: E/SoundPool(1265): error loading /system/media/audio/ui/KeypressSpacebar.ogg
11-20 11:27:36.483: W/AudioService(1265): Soundpool could not load file: /system/media/audio/ui/KeypressSpacebar.ogg
11-20 11:27:36.483: E/SoundPool(1265): error loading /system/media/audio/ui/KeypressDelete.ogg
11-20 11:27:36.483: W/AudioService(1265): Soundpool could not load file: /system/media/audio/ui/KeypressDelete.ogg
11-20 11:27:36.483: E/SoundPool(1265): error loading /system/media/audio/ui/KeypressReturn.ogg
11-20 11:27:36.483: W/AudioService(1265): Soundpool could not load file: /system/media/audio/ui/KeypressReturn.ogg
11-20 11:27:36.483: E/SoundPool(1265): error loading /system/media/audio/ui/KeypressInvalid.ogg
11-20 11:27:36.483: W/AudioService(1265): Soundpool could not load file: /system/media/audio/ui/KeypressInvalid.ogg
11-20 11:27:36.483: W/AudioService(1265): onLoadSoundEffects(), Error -1 while loading samples
11-20 11:27:36.563: W/EGL_emulation(1860): eglSurfaceAttrib not implemented
11-20 11:27:36.733: I/ActivityManager(1265): Displayed com.example.ala/.AircraftActivity: +254ms
11-20 11:27:39.023: E/SoundPool(1265): error loading /system/media/audio/ui/Effect_Tick.ogg
11-20 11:27:39.023: W/AudioService(1265): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
11-20 11:27:39.023: E/SoundPool(1265): error loading /system/media/audio/ui/Effect_Tick.ogg
11-20 11:27:39.023: W/AudioService(1265): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
11-20 11:27:39.023: E/SoundPool(1265): error loading /system/media/audio/ui/Effect_Tick.ogg
11-20 11:27:39.023: W/AudioService(1265): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
11-20 11:27:39.023: E/SoundPool(1265): error loading /system/media/audio/ui/Effect_Tick.ogg
11-20 11:27:39.023: W/AudioService(1265): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
11-20 11:27:39.023: E/SoundPool(1265): error loading /system/media/audio/ui/Effect_Tick.ogg
11-20 11:27:39.023: W/AudioService(1265): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
11-20 11:27:39.023: E/SoundPool(1265): error loading /system/media/audio/ui/KeypressStandard.ogg
11-20 11:27:39.023: W/AudioService(1265): Soundpool could not load file: /system/media/audio/ui/KeypressStandard.ogg
11-20 11:27:39.023: E/SoundPool(1265): error loading /system/media/audio/ui/KeypressSpacebar.ogg
11-20 11:27:39.023: W/AudioService(1265): Soundpool could not load file: /system/media/audio/ui/KeypressSpacebar.ogg
11-20 11:27:39.023: E/SoundPool(1265): error loading /system/media/audio/ui/KeypressDelete.ogg
11-20 11:27:39.023: W/AudioService(1265): Soundpool could not load file: /system/media/audio/ui/KeypressDelete.ogg
11-20 11:27:39.023: E/SoundPool(1265): error loading /system/media/audio/ui/KeypressReturn.ogg
11-20 11:27:39.023: W/AudioService(1265): Soundpool could not load file: /system/media/audio/ui/KeypressReturn.ogg
11-20 11:27:39.023: E/SoundPool(1265): error loading /system/media/audio/ui/KeypressInvalid.ogg
11-20 11:27:39.023: W/AudioService(1265): Soundpool could not load file: /system/media/audio/ui/KeypressInvalid.ogg
11-20 11:27:39.023: W/AudioService(1265): onLoadSoundEffects(), Error -1 while loading samples

2 个答案:

答案 0 :(得分:0)

您没有初始化ExpandableListView

  ...
  setContentView(R.layout.expandable_main);
  lv = (ExpandableListView) findViewById(R.id.your_list_id);

答案 1 :(得分:0)

我不确定这个但是在ExpActivity的代码中你没有这行

 lv = (ExpandableListView)findViewById(R.id.lv_item);

试试这个:

如果没有解决。你可以发布你正在获得LogCat的错误。