I had a problem setting some of the fragment menu items in an ActionBar , and I found a way to solve it, but I donβt understand why this worked.
I wanted to change the visibility of the menu item right after I puffed it from the XML menu file into onCreateOptionsMenu . The code seems to work fine, but there is no visible effect. I solved the problem of inflating the menu in onCreateOptionsMenu , but changing its visibility in the onPrepareOptionsMenu method.
I want to know why changing visibility in onCreateOptionsMenu does not work.
What can I do in onPrepareOptionsMenu , which I cannot do in onCreateOptionsMenu ?
Is there any template?
Thanks!
Here's the appropriate code, just in case:
public class MyFragment extends Fragment { @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); inflater.inflate(R.menu.my_menu, menu);
Gerardo contijoch
source share