onCreateOptionsMenu method does not get called in Fragment class.
See original GitHub issueonCreateOptionsMenu
method does not get called, even after invaliding the menu.
getSlidingMenu().setOnOpenedListener(new OnOpenedListener() { @Override public void onOpened() { supportInvalidateOptionsMenu(); Log.d("SLIDING DRAWER","OPENED"); } });
Called the above inside the BaseActivity onCreate()
and also the FragmentClass which extends the BaseActivity method.
The Fragment class onCreate() method has setHasOptionsMenu(true);
. Still it does not trigger or invoke the onCreateOptionsMenu() method.
Issue Analytics
- State:
- Created 10 years ago
- Comments:10
Top Results From Across the Web
OnCreateOptionsMenu() not called in Fragment - Stack Overflow
In your fragment's onCreateView() method, you need to call setHasOptionsMenu(true) to tell the host activity that your fragment has menu ...
Read more >No warning when not your Activity does not call super in Menu ...
When updated the androidx fragment from 1.4.0 to 1.5.0 the onCreateOptionsMenu is not called anymore. SetHasOptionsMenu(true) is called so the ...
Read more >Fragment | Android Developers
Returns the Transition that will be used to move Views out of the scene when the fragment is removed, hidden, or detached when...
Read more >Creating and Using Fragments | CodePath Android Cliffnotes
onActivityCreated() is called when host activity has completed its onCreate() method. onStart() is called once the fragment is ready to be displayed on...
Read more >Android - onCreateOptionsMenu is deprecated - YouTube
Links:GitHub repo ▻ https://github.com/MrBean355/youtube- android /tree/main/options-menu- ... Your browser can't play this video.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I did the same in my project and it works fine. I extend my fragment as follow SlidingMenuListFragment extends SherlockListFragment I’m using the sherlockactionbar So i extend SherlockListFragment and not just ListFragment. Then I have the following code in my SlidingMenuListFragment .
This works fine for me… As a result I can add menu entries in the xml file displayd in the behindview from the slidingMenu. Hope that helps. In addition I added the following attribute to certain menu entries in the xml file android:visible=“false” because I don’t want them to show up in the actual menu…
@faywong : here is the link which documents this feature http://actionbarsherlock.com/usage.html.
which reads “NOTE: When using SherlockFragmentActivity there are also ‘Sherlock’-prefixed fragment classes which you should use to ensure proper functionality (e.g. SherlockFragment, SherlockListFragment). The activity will still function with the normal fragment classes but you will not be able to use any of the menu-related methods.”