Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fragments overlapping each other

I have an action bar with 3 tabs, each tab opens a fragment. The third tab, "Catalog", has a list: enter image description here

When I click on an item it opens another fragment, which is not part of the action bar:

public void onClick(View v) {
    switch (v.getId())
    {
    case R.id.category1:    
        Fragment cosmeticsFragment = new ActivityCosmetics();
        FragmentTransaction transaction = getFragmentManager().beginTransaction();

        transaction.replace(android.R.id.content, cosmeticsFragment);
        transaction.addToBackStack(null);

        transaction.setTransition(1);

        transaction.commit();
        break;
        ...

This is what it looks like after that: enter image description here

From this point, if I go to other tab and then return to the Catalog tab, I see the 2 previous fragments overlapping each other:

enter image description here

How do I prevent it from happening?

like image 781
Igal Avatar asked Apr 10 '13 09:04

Igal


1 Answers

Setting a background to fragment layout would fix this.

like image 176
Asad Haider Avatar answered Oct 09 '22 00:10

Asad Haider