Android onChildClick未打开活动

Android onChildClick未打开活动,android,expandablelistview,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 andr

大家早上好。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


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
11-20 11:27:02.782:I/ActivityManager(1265):显示com.example.ala/.Splash:+1s213ms
11-20 11:27:03.122:I/ActivityManager(1265):从pid 1860启动u0{act=com.example.ala.MAINACTIVITY cmp=com.example.ala/.MAINACTIVITY}
11-20 11:27:03.232:D/dalvikvm(1860):释放14K的所有元素的GC_,3%的自由元素8163K/8364K,暂停3ms,总计5ms
11-20 11:27:03.232:I/dalvikvm堆(1860):对于2073612字节分配,将堆(frag大小写)增长到10.125MB
11-20 11:27:03.242:D/dalvikvm(1860):释放3K的所有元素的GC_,3%的自由元素10184K/10392K,暂停2ms,总计2ms

11-20 11:27:03.282:D/android.widget.GridLayout(1860):水平约束:x1-x0>=174,x2-x1>=174,x3-x2>=174,x3-x0您没有初始化
ExpandableListView

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

我不确定这一点,但在ExpActivity中的代码中没有这一行

 lv = (ExpandableListView)findViewById(R.id.lv_item);
试试这个:


如果不解决的话。您可以发布您得到的行日志的错误。

您试过调试它吗?也就是说,在侦听器中的
if块
之外放置一个日志?在你的问题中张贴日志。这是至关重要的信息。我不知道除了作为文本之外,如何添加LogaCat。希望这有帮助。谢谢。你的应用程序崩溃了吗?这看起来不像是来自应用程序的错误,而是来自android系统的错误。在你的
onChildClick
方法中放入一个
Log.e(“,”test”)
,看看它是否被打印出来。应用程序没有崩溃,我有一个日志语句,但没有打印出来。这不起作用,我在日志猫上看到的唯一错误是SoundPool,AudioService刚才乔纳森·佩雷斯
 lv = (ExpandableListView)findViewById(R.id.lv_item);