错误地区分孩子'可扩展列表视图中的操作

时间:2015-12-07 19:48:38

标签: android android-intent switch-statement parent-child expandablelistview

我在片段中有一个简单的可扩展列表视图,只有两个级别的列表:父级子级

我想在点击孩子时部署方法,以便每个孩子打开不同的活动。

现在,我在我的" expListView"上使用了 setOnChildClickListener 。这样

        expListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {

        @Override
        public boolean onChildClick(ExpandableListView parent, View view,
                                    int groupPosition, int childPosition, long id) {
            switch (groupPosition) {
                case 0:
                    switch (childPosition) {
                        case 0:
                            Intent Open00 = new Intent(getActivity(), First.class);
                            getActivity().startActivityForResult(Open00, 0);
                            getActivity().overridePendingTransition(R.anim.bounce, R.anim.bounce);
                            break;
                        case 1:
                            Intent Open01 = new Intent(getActivity(), Second.class);
                            getActivity().startActivityForResult(Open01, 0);
                            getActivity().overridePendingTransition(R.anim.bounce, R.anim.bounce);
                            break;
                    }

                case 1:
                    switch (childPosition) {
                        case 0:
                            Intent Open1 = new Intent(getActivity(), Popup1.class);
                            getActivity().startActivityForResult(Open1, 1);
                            getActivity().overridePendingTransition(R.anim.bounce, R.anim.bounce);
                            break;
                        case 1:
                            Intent Open2 = new Intent(getActivity(), Popup2.class);
                            getActivity().startActivityForResult(Open2, 1);
                            getActivity().overridePendingTransition(R.anim.bounce, R.anim.bounce);
                            break;
                    }
                case 2:
                    switch (childPosition) {
                        case 2:

                            break;
                        case 3:

                            break;
                    }
            }
            return false;
        }
    });

现在发生的事情是,如果我点击第一个组的第一个孩子(数字 0 )(数字 0 ,它会打开两个活动,即 0 中的数字 0 和< 0 强> 1

我想知道为什么,因为我也使用了开关来解决这个问题。

提前致谢

1 个答案:

答案 0 :(得分:0)

我找到了,jeez!

        expListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {

        @Override
        public boolean onChildClick(ExpandableListView parent, View v,
                                    int groupPosition, int childPosition, long id) {
            switch (groupPosition) {
                case 0:
                    switch (childPosition) {
                        case 0:
                            Intent Open00 = new Intent(getActivity(), First.class);
                            getActivity().startActivityForResult(Open00, 0);
                            getActivity().overridePendingTransition(R.anim.bounce, R.anim.bounce);
                            break;
                        case 1:
                            Intent Open01 = new Intent(getActivity(), Second.class);
                            getActivity().startActivityForResult(Open01, 0);
                            getActivity().overridePendingTransition(R.anim.bounce, R.anim.bounce);
                            break;
                    }
                    **break**;

                case 1:
                    switch (childPosition) {
                        case 0:
                            Intent Open1 = new Intent(getActivity(), Popup1.class);
                            getActivity().startActivityForResult(Open1, 1);
                            getActivity().overridePendingTransition(R.anim.bounce, R.anim.bounce);
                            break;
                        case 1:
                            Intent Open2 = new Intent(getActivity(), Popup2.class);
                            getActivity().startActivityForResult(Open2, 1);
                            getActivity().overridePendingTransition(R.anim.bounce, R.anim.bounce);
                            break;
                    }
                    break;
                case 2:
                    switch (childPosition) {
                        case 2:

                            break;
                        case 3:

                            break;
                    }
                    **break**;
                case 3:
                    switch (childPosition) {
                        case 0:

                            break;
                        case 1:

                            break;
                    }
                    **break**;
            }
            return false;
        }
    });

我忘了在小组结尾处进入休息时间!