如何重置或重新加载片段容器以使其为空。我有一个主详细信息视图,我想在单击菜单项时将详细信息容器重置为空。这在某些情况下有效,在某些情况下无效。
NullFragment fragment = new NullFragment();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager
.beginTransaction();
fragmentTransaction.replace(R.id.item_detail_container,
fragment);
int count = fragmentManager.getBackStackEntryCount();
fragmentManager.popBackStackImmediate(count, 0);
fragmentTransaction.commit();