0

我正在使用ExpandableListViewAndroid。我必须通过单击孩子来调用不同的活动。每个孩子都必须指导我进行新的活动。请告诉我我该怎么做。

我的代码有点像:

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;
        }

    });
4

1 回答 1

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;
        }

    });
于 2012-05-22T05:13:48.717 回答