当通过导航抽屉replace之前的片段到新的片段时,在新的片段中排除前面的片段响应

我有导航drawar共有12个片段..每个片段都有抽排方法。 除了位置= 1和位置= 5片段之外,每个片段都显示自己的齐射响应。

当我的应用程序启动

情况1:我打开位置1片段,打开位置5片段后,两个片段都有位置1片段响应。

情况2:如果我打开位置5的片段,打开后的位置1片段比两个片段都有位置1的片段响应。

情景1图像:

FragmentInbox FragmentLaws

情景2图像:

FragmentLaws FragmentInbox

我的片段交易方法类:

private void showFragment(Fragment fragment) { llContainer = (LinearLayout)findViewById(R.id.container); if (fragment != null) { llContainer.removeAllViewsInLayout(); FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.container, fragment, fragment.getClass().getName()); fragmentTransaction.commit(); fragmentManager.popBackStack(); } } @Override public void onItemSelected(int position) { Fragment frag = null; switch (position) { case POS_HOME: frag = FragmentHome.instance(screenTitles[position]); break; case POS_INBOX: txtToolbarTitle.setVisibility(View.VISIBLE); txtToolbarTitle.setText("Notifications"); frag = FragmentInbox.instance(screenTitles[position]); break; case POS_LOG: frag = FragmentLog.instance(screenTitles[position]);; break; case POS_BOOK: frag = FragmentBook.instance(screenTitles[position]); break; case POS_BUILDING: frag = FragmentBuilding.instance(screenTitles[position]); break; case POS_LAWS: frag = FragmentLaws.instance(); break; case POS_DOCUMENT: frag = FragmentDocument.instance(screenTitles[position]); break; case POS_EVENT: frag = FragmentEvent.instance(screenTitles[position]); break; case POS_BOARD: frag = FragmentBoard.instance(screenTitles[position]); break; case POS_AROUND: frag = FragmentAround.instance(screenTitles[position]); break; case POS_PROFILE: frag = FragmentProfile.instance(screenTitles[position]); break; case POS_CONCIERGE: frag = FragmentConcierge.instance(screenTitles[position]); break; } showFragment(frag); mSlideMenu.closeMenu(); } 

Solutions Collecting From Web of "当通过导航抽屉replace之前的片段到新的片段时,在新的片段中排除前面的片段响应"