I have 2 Fragment
's - A and B.
In order to switch from Fragment
A to Fragment
B I'm using this function:
public static void swapFragments(FragmentManager fragmentManager, int containerViewId, Fragment newFragment) {
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(containerViewId, newFragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
Let's say Fragment
A takes the entire screen's area and Fragment
B takes only the upper half of the screen.
The problem: When switching to Fragment
B, the user is still able to see Fragment
A at the lower half of the screen...
How can I hide Fragment
A when switching to Fragment
B ?
p.s: I don't want to use replace
instead of add
in the swap
function above - I don't want Fragment
A's onCreate()
to be called each time the user navigate back from Fragment
B to Fragment
A...
Thanks in advance.