How to remove stack fragment menu items?

I have a fragment that I am replacing with another, and also adding a transaction to the back stack. Both of my snippets provide menu items in the action bar using ActionBarSherlock. However, I have a problem - in the second fragment on the action bar both the first fragment and the second fragment are displayed; I want only the second. Is there any way to achieve this?

(I also use the support library.)

+6
source share
2 answers

If you want to update the action bar icons, you can override onCreateOptionsMenu () in the action to determine which menu is used for the active fragment. Then call invalidateOptionsMenu () after replacing fragments to recreate the menu.

If you use only the drop-down menu, you can override onPrepareOptionsMenu () and add / remove items from the menu.

+3
source

Perhaps you had a ViewPager in the first snippet with getFragmentManager() passed to the FragmentPagerAdapter constructor. And then you tried to go to the second fragment using the same getFragmentManager() .

If so, go getChildFragmentManager() to FragmentPagerAdapter .

0
source

Source: https://habr.com/ru/post/917260/


All Articles