Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fragment visible on the background

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.

like image 758
DroidBender Avatar asked Oct 08 '22 05:10

DroidBender


1 Answers

Make sure you don't use a static fragment relation to an XML by setting the first fragment as "android:name" in the layout.

Make with framelayouts the layout of the XML and add the fragments flexibly as shown in this tutorial:

http://developer.android.com/training/basics/fragments/fragment-ui.html

like image 84
Boy Avatar answered Oct 13 '22 10:10

Boy