I am working on an application that has three fragments which are defined in an XML file:
[HeaderFragment]
[MainFragment]
[FooterFragment]
The first screen initiates the three fragments, the Header- and FooterFragment are static so will not change content.
The MainFragment is initial a menu with buttons and a transparant background (MenuFragment
). When I click an item in the menu I replace the MenuFragment
with a new fragment (DetailsFragment
) like this:
FragmentTransaction transaction = mFragmentManager.beginTransaction();
Fragment newFragment = new DetailFragment();
transaction.replace(R.id.content_container, newFragment);
transaction.addToBackStack(newFragment.getTag());
transaction.commit();
The DetailFragment
shows up and when I press back, the MenuFragment
appears and everything works how it should.
Here is my problem:
Inside my DetailFragment
, I have a toggle option to filter the content, this is a button. When this is clicked, the DetailFragmentFiltered
replaces the DetailFragment
on the same way as the code above states. The only difference is that I don't add it to the BackStack because after filtering and pressing Back.. I still want to return to the MenuFragment
.
When I clicked the filter button and press Back, the DetailFragment
(or DetailFragmentFiltered
) is shown behind my MenuFragment
. Afcourse, I don't want this.