1

I have an activity with a navigation drawer and fragments (Fragment Lvl 1). One of these fragments contains nested children(Fragment Lvl 2) with a viewpager adapter. When I add an option menu to the nested child (Lvl 2) it stills appearing on the newely displayed fragment when I'm switching between fragement (Lvl 1) from the navigation drawer.

It's seems like the Fragment wich containing the view pager is not telling the activity that is has been hidden or whatever.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62

2 Answers2

1

I had the similar issue because I was providing getFragmentManager() to FragmentPagerAdapter constructor instead of getChildFragmentManager().

mixel
  • 25,177
  • 13
  • 126
  • 165
0

Finally I solved that by calling Menu.clear() on onDetach() in the nested fragment (Lvl2).

But it will be nice , if someone could provide me a better solution.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • I have the exactly same situation like yours. However, my solution is manually calling `invalidateOptionsMenu()` in the `onNavigationItemSelected()` of main activity after switching between level 1 fragments. – 正宗白布鞋 Nov 23 '16 at 14:23