无论选择哪个groupView,都只显示一个片段。

时间:2015-07-08 19:29:08

标签: android android-fragments expandablelistview

我在导航抽屉中包含一个ExpandableListView,并且每个ExpandableListView组都应该将用户带到两个片段之一:AssignmentManagerFragment和SubjectManagerFragment。组中的第三个视图设置为将用户带到SubjectManagerFragment,但由于某种原因, ALL 将用户带到AssignmentManagerFragment。知道为什么,或者可以做些什么来解决它?

这是我的代码:

drawerList.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
        @Override
        public boolean onGroupClick(ExpandableListView parent, View v,
                                    int groupPosition, long id){
            Fragment fragment;
            FragmentManager fragmentManager;
            Bundle args;
            switch (groupPosition) {
                case 0:
                    fragment = new AssignmentManagerFragment();
                    fragmentManager = getFragmentManager();
                    args = new Bundle();
                    args.putString(AssignmentManagerFragment.ARG_PARAM1, "" + groupPosition);
                    fragment.setArguments(args);
                    fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
                    if (drawerList.isGroupExpanded(groupPosition)) {
                        drawerList.collapseGroup(groupPosition);
                    } else {
                        drawerList.expandGroup(groupPosition, false);
                    }
                    Toast.makeText(getBaseContext(), "Clicked On grooop: " + v.getTag() + "|" + groupPosition,
                            Toast.LENGTH_LONG).show();

                case 1:
                    fragment = new AssignmentManagerFragment();
                    fragmentManager = getFragmentManager();
                    args = new Bundle();
                    args.putString(AssignmentManagerFragment.ARG_PARAM1, "" + groupPosition);
                    fragment.setArguments(args);
                    fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
                    if (drawerList.isGroupExpanded(groupPosition)) {
                        drawerList.collapseGroup(groupPosition);
                    } else {
                        drawerList.expandGroup(groupPosition, false);
                    }
                    Toast.makeText(getBaseContext(), "Clicked On grooop: " + v.getTag() + "|" + groupPosition,
                            Toast.LENGTH_LONG).show();

                case 2:
                    fragment = new SubjectManagerFragment();
                    fragmentManager = getFragmentManager();
                    args = new Bundle();
                    args.putString(SubjectManagerFragment.ARG_PARAM1, "" + groupPosition);
                    fragment.setArguments(args);
                    fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
                    Toast.makeText(getBaseContext(), "Clicked On grooop: " + v.getTag() + "|" + groupPosition,
                            Toast.LENGTH_SHORT).show();
                    drawer.closeDrawer(drawerList);

                case 3:
                    fragment = new AssignmentManagerFragment();
                    fragmentManager = getFragmentManager();
                    args = new Bundle();
                    args.putString(AssignmentManagerFragment.ARG_PARAM1, "" + groupPosition);
                    fragment.setArguments(args);
                    fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
                    if (drawerList.isGroupExpanded(groupPosition)) {
                        drawerList.collapseGroup(groupPosition);
                    } else {
                        drawerList.expandGroup(groupPosition, false);
                    }
                    Toast.makeText(getBaseContext(), "Clicked On grooop: " + v.getTag() + "|" + groupPosition,
                            Toast.LENGTH_LONG).show();

                case 4:
                    fragment = new AssignmentManagerFragment();
                    fragmentManager = getFragmentManager();
                    args = new Bundle();
                    args.putString(AssignmentManagerFragment.ARG_PARAM1, "" + groupPosition);
                    fragment.setArguments(args);
                    fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
                    if (drawerList.isGroupExpanded(groupPosition)) {
                        drawerList.collapseGroup(groupPosition);
                    } else {
                        drawerList.expandGroup(groupPosition, false);
                    }
                    Toast.makeText(getBaseContext(), "Clicked On grooop: " + v.getTag() + "|" + groupPosition,
                            Toast.LENGTH_LONG).show();
            }
            return true;
        }

    });

1 个答案:

答案 0 :(得分:0)

我在每个案件后忘了休息陈述。 onGroupClickListener没有任何功能上的错误;这是一个简单的编码错误,但它可以作为匆忙编码的一个很好的例子。