Fragments overlapping each other

后端 未结 4 1053
囚心锁ツ
囚心锁ツ 2020-12-31 02:01

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

4条回答
  •  余生分开走
    2020-12-31 02:20

    You can manage your fragments by searching them by tag. When adding fragment to backstack add TAG name

    transaction.addToBackStack("myCustomFragmentTag");
    

    If you want to destroy Fragment anywhere in application :

    Fragment previousInstance = getFragmentManager().findFragmentByTag("myCustomFragmentTag");
                    if (previousInstance != null)
                        transaction.remove(previousInstance);
    

    You can try override some behavior so this line of code 'll destroy initialized last Fragment

    getFragmentManager().popBackStack(); 
    

提交回复
热议问题