I am having trouble getting the following piece of code to work out. I have a viewpager
with 3 fragments, and I want a search icon to only show up on one. I s
I used Nermeen's answer and managed to get it without any delay.
I don't inflate anything in onCreateOptionsMenu
, but use it to get a reference to the menu:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
customMenu = menu;
return super.onCreateOptionsMenu(menu);
}
Then, in onPrepareOptionsMenu()
, I call the viewpager getCurrentItem()
(should be something like viewPager.getCurrentItem()
), call invalidateOptionsMenu()
and inflate whatever menu I want in that page using the customMenu reference I created in onCreateOptionsMenu()
.