package com.example.dell.otheractivity;import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
public class ExpandableListActivity extends android.app.ExpandableListActivity {
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        ExpandableListAdapter adapter = new BaseExpandableListAdapter() {
            int[] logos = new int[]
                    {
                            R.drawable.c1,R.drawable.c2,R.drawable.c3
                    };
            private String[] armTypes = new String[]
                    {
                            "神","人","虫"
                    };
            private String[][] arms = new String[][]
                    {
                            {"狂战","龙骑","暗黑圣堂","电兵"},
                            {"小狗","刺蛇","飞龙","自爆飞机"},
                            {"机枪兵","护士","幽灵"}
                    };
            //获取指定组位置、指定子列表项
            @Override
            public Object getChild(int groupPosition, int childPosition) {
                return arms[groupPosition][childPosition];
            }
            @Override
            public long getChildId(int groupPosition, int childPosition) {
                return childPosition;
            }
            @Override
            public int getChildrenCount(int groupPosition) {
                return arms[groupPosition].length;
            }
            private TextView getTextView()
            {
                AbsListView.LayoutParams lp = new AbsListView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,64);
                TextView textView = new TextView( ExpandableListActivity.this);
                textView.setLayoutParams(lp);
                textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
                textView.setPadding(36,0,0,0);
                textView.setTextSize(20);
                return textView;
            }            //该方法决定每个子选项的外观
            @Override
            public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
                TextView textView = getTextView();
                textView.setText(getChild(groupPosition,childPosition).toString());
                return textView;
            }            //获取指定位置处的数据
            @Override
            public Object getGroup(int groupPosition) {
                return armTypes[groupPosition];
            }
            @Override
            public int getGroupCount() {
                return armTypes.length;
            }
            @Override
            public long getGroupId(int groupPosition) {
                return groupPosition;
            }
            //该方法决定每个组选项的外观
            @Override
            public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
                LinearLayout ll = new LinearLayout( ExpandableListActivity.this);
                ll.setOrientation(0);
                ImageView logo = new ImageView( ExpandableListActivity.this);
                logo.setImageResource(logos[groupPosition]);
                ll.addView(logo);
                TextView textView = getTextView();
                textView.setText(getGroup(groupPosition).toString());
                ll.addView(textView);
                return ll;
            }            @Override
            public boolean hasStableIds() {
                return true;
            }            @Override
            public boolean isChildSelectable(int groupPosition, int childPosition) {
                return true;
            }
        };
        setListAdapter(adapter);
    }
}android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.dell.otheractivity/android.app.ExpandableListActivity}; have you declared this activity in your AndroidManifest.xml?
                                                     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
                                                     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
                                                     at android.app.Activity.startActivityForResult(Activity.java:3441)
                                                     at android.app.Activity.startActivityForResult(Activity.java:3402)
                                                     at android.app.Activity.startActivity(Activity.java:3644)
                                                     at android.app.Activity.startActivity(Activity.java:3612)
                                                     at android.app.LauncherActivity.onListItemClick(LauncherActivity.java:404)
                                                     at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
                                                     at android.widget.AdapterView.performItemClick(AdapterView.java:299)
                                                     at android.widget.AbsListView.performItemClick(AbsListView.java:1129)
                                                     at android.widget.AbsListView$PerformClick.run(AbsListView.java:2927)
                                                     at android.widget.AbsListView$3.run(AbsListView.java:3676)
                                                     at android.os.Handler.handleCallback(Handler.java:733)
                                                     at android.os.Handler.dispatchMessage(Handler.java:95)
                                                     at android.os.Looper.loop(Looper.java:136)
                                                     at android.app.ActivityThread.main(ActivityThread.java:5050)
                                                     at java.lang.reflect.Method.invokeNative(Native Method)
                                                     at java.lang.reflect.Method.invoke(Method.java:515)
                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:806)
                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
                                                     at dalvik.system.NativeStart.main(Native Method)

解决方案 »

  1.   

    已经在AndroidManifest声明了Activity,但是还是报错
    android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.dell.otheractivity/android.app.ExpandableListActivity}; have you declared this activity in your AndroidManifest.xml?
      

  2.   

    activity的类名不要和父类同名,换个类名试试
      

  3.   

    话说lz怎么写出来的,刚试了一下子父类同名,as应该会提示删除当前子类的
      

  4.   

    android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.dell.otheractivity/android.app.ExpandableListActivity}; 
    错误信息显示的你显示调用的Activity是android.app.ExpandableListActivity,你调用的时候导错包了吧