从expandableListView的onChildClick启动新的Activity

时间:2012-05-22 05:05:32

标签: android android-intent

我在Android上使用ExpandableListView。我必须通过点击孩子来打电话给不同的活动。每个孩子都必须指导我开展新的活动。请告诉我该怎么做。

我的代码有点像:

list.setOnChildClickListener(new OnChildClickListener() {
    public boolean onChildClick(ExpandableListView parent, View v,
        int groupPosition, int childPosition, long id) {
        // TODO Auto-generated method stub
        ExpandableListAdapter adap = parent.getExpandableListAdapter();
        int gp = (int) adap.getGroupId(groupPosition);
        int cp = (int) adap.getChildId(groupPosition, childPosition);
        if (gp == 0) {
            switch (cp) {
            case 0:
                Intent intent = new Intent(getApplicationContext(),
                    Test11.class);
                    break;
                case 1:
                Intent intent = new Intent(getApplicationContext(),
                            Test12.class);
                }
            } else if (gp == 1) {
                switch (cp) {
                case 0:
                Intent intent = new Intent(getApplicationContext(),
                            Test21.class);
                    break;
                case 1:
                Intent intent = new Intent(getApplicationContext(),
                            Test22.class);
                    break;
                }
            }

            return true;
        }

    });

1 个答案:

答案 0 :(得分:0)

也许我相信你缺少startActivity(),

list.setOnChildClickListener(new OnChildClickListener() {
    public boolean onChildClick(ExpandableListView parent, View v,
        int groupPosition, int childPosition, long id) {
        // TODO Auto-generated method stub
        ExpandableListAdapter adap = parent.getExpandableListAdapter();
        int gp = (int) adap.getGroupId(groupPosition);
        int cp = (int) adap.getChildId(groupPosition, childPosition);
        if (gp == 0) {
            switch (cp) {
            case 0:
                Intent intent = new Intent(getApplicationContext(),
                    Test11.class);
                 startActivity(intent);
                    break;
                case 1:
                Intent intent = new Intent(getApplicationContext(),
                            Test12.class);
                startActivity(intent);
                }
            } else if (gp == 1) {
                switch (cp) {
                case 0:
                Intent intent = new Intent(getApplicationContext(),
                            Test21.class);
               startActivity(intent);
                    break;
                case 1:
                Intent intent = new Intent(getApplicationContext(),
                            Test22.class);
               startActivity(intent);
                    break;
                }
            }

            return true;
        }

    });