Questions tagged [oncreateoptionsmenu]

112 questions
1
vote
1 answer

onCreateOptionsMenu not called on SherlockFragment under FragmentPagerAdapter

I have a SherlockFragment that works properly when inflated in a SherlockActivity. I set setHasOptionsMenu(true) on onCreate() and onCreateOptionsMenu() function in that fragment is properly called. The problem is when I call the fragment under a…
1
vote
1 answer

Stop onCreateOptionsMenu() to be called from detached Fragment

I know there is LOT of code but please read the first paragraph and go further if you need more info ! Thanks! I want to display contextual menu item in my 3 tabs activity (no view pager), just static tabs. The main activity is the…
1
vote
3 answers

Android: onCreateOptionsMenu - Remove Default Menu Item

I am using the onCreateOptionsMenu and there is a default menu item that I did not program. I would like to remove it because I have no use for it and it does not do anything. Here is what it looks like: I would like to get rid of the "Settings"…
lord_sneed
  • 794
  • 3
  • 12
  • 25
0
votes
1 answer

Kotlin: Make the options menu visible only in a specific toolbar

There are three types of toolbar used in this app. (toolbar, toolbar2, toolbar3) The MainActivity is connected to four fragments through the bottom navigation bar. (home, community, calendar, mypage) toolbar - used in "MainActivity" (home,…
0
votes
0 answers

How do I call onCreateMenuOptions just once when the fragment is being created

My activity contains many fragments and it has been found that every time a bottom sheet fragment opens up in the activity, the onCreateOptionsMenu function gets called again. How do I ensure that the function gets called only during the start of…
0
votes
1 answer

Options menu inflate wrongly in viewpager2

I have 4 fragments but for each fragments it has different different menu options in my app with viewpager2 so the user swipe through these all fragments and when the app starts the menu option for the first fragment showing the wrong which is 4th…
0
votes
1 answer

Programatically create checkbox menu in fragment java

I am having a Fragment and below is how i am adding menus in my onCreateOptionsMenu programatically @Override public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { menu.add(0, 0, 0, new…
0
votes
1 answer

onCreateOptionsMenu showing alwasy as action with a menu that i have created programatically

Below is how i have created my menu programmatically @Override public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); menu.add(0, 0, 0, new…
0
votes
1 answer

Cannot call inline fun SearchView.OnQueryTextListener from onCreateOptionsMenu

In this app I tried to implement SearchView.OnQueryTextListener in separate kotlin file like this import androidx.appcompat.widget.SearchView inline fun SearchView.OnQueryTextListener(crossinline listener: (String) -> Unit) { …
Dr Mido
  • 2,414
  • 4
  • 32
  • 72
0
votes
1 answer

Android onCreateOptionsMenu declaration in a fragment failing with "Accidental Override"

I have some Kotlin code that is attempting to tweak the visibility of some option menu items inside a fragment using onCreateMenuOptions. Kotlin is complaining about an accidential override, and there being dual onCreateMenuOption declarations in…
0
votes
0 answers

Search Menu not showing in Fragment

I was trying to build a simple fragment in which to show search on the menu, in the debugging doesn't stop at the class. I have other classes for the main Fragment and other 2 fragments, I want to show the search as 2 options at the header or inside…
0
votes
0 answers

What is safe to put in OnCreateOptionsMenu in Android Activity?

In my app I have a Spinner as a menu item in the action bar of my Activity. It has the collapsible action view so it appears only when the icon is clicked. I obtain a reference to my Spinner like this: @Override public boolean…
0
votes
0 answers

crash on MainMenu.onCreateOptionsMenu

When I test my app on Xiaomi A2, it runs fine. When I upload to Google Play, it crashes. Stack Trace on Play console reads: java.lang.NullPointerException: at com.thongjoon.ocsc_exam_prep.MainMenu.onCreateOptionsMenu (MainMenu.java:29) at…
tjkh
  • 1
  • 1
0
votes
1 answer

How do I only trigger onPrepareOptionsMenu and not onCreateOptionsMenu?

According to the Android menu documentation and a similar question, onPrepareOptionsMenu should be used to update menus dynamically. For Android 3.0 and higher, the documentation says: When an event occurs and you want to perform a menu update, you…
ByteHamster
  • 4,884
  • 9
  • 38
  • 53
0
votes
1 answer

Android 5 portrait app crashes when going to Recents and rotating

The activities of my app have all the attribute to make them portrait: android:screenOrientation="portrait" The minSdkVersion of the app is 21. With Android 5.0 phones the app crashes if the device is using the autorotate setting and the app goes…