Skip to content
Advertisement

onCreateOptionsMenu not being called

onCreateOptionsMenu does not get called in a fragment. I have to manually call setHasOptionsMenu(true) in onCreatedView() but this causes the item.itemId be an empty String "" in the onOptionsItemSelected() and therefore i can’t detect which menu item was tapped.

I’m currently using this in a fragment:

JavaScript

Advertisement

Answer

Call super.onCreateOptionsMenu(menu,inflater) after menu inflate

JavaScript

This may more help Ref :: https://stackoverflow.com/a/15654039/11393354

try this,

JavaScript

And in onCreate add this line to make the options appear in your Toolbar

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement