If it helps, what I want is similar to what is done in this google tutorial
But there a fragment is created prior to the transition. If I do that t
You are combining two different methods of changing which Fragment is shown:
replace()
to replace the contents of the container with a different Fragmenthide()
to remove a Fragment, then calling show()
to show another Fragment.Pick one method and stick with it. The Building a Flexible UI guide uses just the replace()
method, so I would start by trying to remove all of your calls to show()
and hide()
.
Also see Android Fragments: When to use hide/show or add/remove/replace? for a quick summary of when it might be beneficial to use hide/show instead of replace.
Try to initialize fragments in that way:
private void initFragments() {
mDiceTable = new DiceTable();
mLogger = new Logger();
isDiceTableVisible = true;
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.add(R.id.fragment_container, mDiceTable);
ft.add(R.id.fragment_container, mLogger);
ft.hide(mLogger);
ft.commit();
}
And then flip between them in that way:
private void flipFragments() {
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
if (isDiceTableVisible) {
ft.hide(mDiceTable);
ft.show(mLogger);
} else {
ft.hide(mLogger);
ft.show(mDiceTable);
}
ft.commit();
isDiceTableVisible = !isDiceTableVisible;
}