How can i reset or reload a fragment container, to make it empty. I have a master detail view and i want to reset the detail container to empty on a menu item click.This works in some cases and does not in some.
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();
Usually you simply remove the fragment from it.
For example do something like
this will
remove
the fragment from theyour_container
holding it.This gets the fragment currently present in your_container
and this remove the fragment
EDIT
Also sometimes it is useful to ensure all transactions are performed and finished, this can be done by using