I'm using an OnClickListener to do a fragment replacement. I'm toggling 3 LinearLayouts to 'GONE' within the OnClickListener also.
I would like to add a function to set the 3 LinearLayouts back to VISIBLE when the back button is pressed. The fragments swap back, but the LinearLayouts don't change their state.
Any help is appreciated, thanks!
final OnClickListener swapFragments = new OnClickListener() {
@Override
public void onClick(View v) {
if (myAdapter.isEmpty() != true) {
FragmentTransaction ft = getFragmentManager()
.beginTransaction();
FragmentTwoTop ftt = new FragmentTwoTop();
FragmentTwoBottom ftb = new FragmentTwoBottom();
ft.replace(R.id.leftTopHolder, ftt, "fragmenttwotop");
ft.replace(R.id.leftBottomtHolder, ftb, "fragmenttwobottom");
layoutOne.setVisibility(View.GONE);
layoutTwo.setVisibility(View.GONE);
layoutThree.setVisibility(View.GONE);
ft.addToBackStack("swapfragments");
ft.commit();
} else {
}
}
};
You could try adding a listener to the backstack: http://developer.android.com/reference/android/app/FragmentManager.html#addOnBackStackChangedListener(android.app.FragmentManager.OnBackStackChangedListener)
It will be called any time "something" is added or removed from/to the backstack.
You can then check the type of the class of the fragment (or maybe your holding the current fragment in a class - your Activity - variable) to decide if it's necessary to execute your animation.
The method in which you manage the layouts could simply check the visibility (getVisibility
) and if it's VISIBLE
then set to GONE
, if it's GONE
set to VISIBLE
.