I thought that creating a custom method in my Activity class where I can change the visibility of a MenuItem and accessing it from the Fragment would work. Sadly, it did not.

It seems that the Fragment class has a method called setHasOptionsMenu(boolean) and you need to call that from within the onCreateView() method in order to be able to manipulate MenuItems from within onCreateOptionsMenu().

So this is how a sample Fragment class will look like.

This code looks for the MenuItem and hides it.

Related Posts Plugin for WordPress, Blogger...