Hide and show Fragments using a FragmentTransaction

Fragment is a child of Object and not View so one cannot call:

fragment.setVisibility(View.INVISIBLE);

Instead we can use a FragmentTransaction to hide or show a fragment.

From the holder activity or a fragment:

FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.hide(myFrag);
ft.commit();

Note that multiple fragments can be hidden or shown before the commit by making multiple calls to ft.hide(…) or ft.show(…).

This flow will work with all the FragmentTransaction actions; add, remove, show, hide, attach, and detach.

http://developer.android.com/reference/android/app/FragmentTransaction.html




4 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *