logo
down
shadow

How to implement onOptionsItemSelected for Sub-Menu Items?


How to implement onOptionsItemSelected for Sub-Menu Items?

By : Vinnie111
Date : November 25 2020, 07:22 PM
may help you . In my case, worked when I implemented a switch for each item selected. It was not necessary implement a listener method.
code :


Share : facebook icon twitter icon
onOptionsItemSelected isn't picking the right clicked menu item

onOptionsItemSelected isn't picking the right clicked menu item


By : Stefan
Date : March 29 2020, 07:55 AM
I hope this helps . The normal thing to do is to define the Menu and its items in xml as a resource - then you can define your own id's to the items. Here's the android developer guide on how to do it with xml.
Another quick fix is to not use the id in onOptionsItemSelected() and instead use MenuItem.getTitle() which you have defined (i.e "Save", "Search", "Refresh").
get Menu outside onOptionsItemSelected

get Menu outside onOptionsItemSelected


By : user2518777
Date : March 29 2020, 07:55 AM
like below fixes the issue Simple answer: Call findItem() on the Menu after you have inflated your menu resource in onCreateOptionsMenu(), and hold onto that MenuItem in a data member of your activity, so you can use it later.
Slightly less-simple answer: Hold onto the Menu from onCreateOptionsMenu() in a data member of your activity, and use it later to find your item.
Why are onPrepareOptionsMenu(Menu menu) and onOptionsItemSelected(MenuItem item) not displaying any menu?

Why are onPrepareOptionsMenu(Menu menu) and onOptionsItemSelected(MenuItem item) not displaying any menu?


By : user3548486
Date : March 29 2020, 07:55 AM
I wish this helpful for you You should call setHasOptionMenu(true) in the onCreate of your Fragment.
Context for onOptionsItemSelected in app-wide menu

Context for onOptionsItemSelected in app-wide menu


By : Amlan
Date : March 29 2020, 07:55 AM
wish helps you This app has just two activities. MainActivity was renamed to SpecialsActivity. The other activity is PizzaActivity. Using the BottomNavigationView, I want to navigate between the two activities. So far, the app opens in SpecialsActivity, and the pizza button does open the PizzaActivity. But then it will not switch back to the SpecialsActivity. I think the issue is related to context. Please help. , Try changing
code :
Intent pizza_intent = new Intent(getApplicationContext(), PizzaActivity.class);
Intent pizza_intent = new Intent(this, PizzaActivity.class);
onOptionsItemSelected not working with my menu

onOptionsItemSelected not working with my menu


By : user3447022
Date : March 29 2020, 07:55 AM
wish of those help I have a toolbar in my MainActivity.kt which has assigned the app:menu="@menu/top_menu: , I think you need inflate your menu:
code :
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
  inflater.inflate(R.menu.top_menu, menu)
  super.onCreateOptionsMenu(menu, inflater)
}
Related Posts Related Posts :
  • Change Spinner DropDown width
  • Samsung Galaxy S4 Screen Size
  • Android text style missing light, medium, thin,
  • Android Studio gradle build failed for hello world app
  • Slide a layout up from bottom of screen
  • Play HTML5 video in iOS/Android native media player
  • How to rescale a bitmap file in android?
  • No view found for id 0x for fragment after rotation?
  • Define different themable styles to the same widget types
  • ProGuard not working in my app
  • FragmentTransaction from BaseAdapter
  • Connecting multiple devices in a Wifi Direct group
  • Why TabActivity is deprecated in android
  • How to capture low resolution picture using android camera
  • android preferenceactivity padding in landscape orientation
  • How can I store cookie in webview?
  • Passing variables from one activity to another
  • Create Multicolored Pie Chart in Android Studio
  • how to kill progress dialog in android
  • Show Error on the tip of the Edit Text Android
  • How do I use getWindowManager() by another java file
  • fetching images from gallery on android phones with internal storage
  • How to discover devices like Google TV and Nexus-Q using MediaRoute API on Android?
  • "Unfortunately your app stopped working"- Facebook Integration for Android
  • How to animate button in android?
  • Resource Not Found Exception in class without context or activity
  • Launching Android Netflix App And Passing Video Id
  • Making a Phone Call with a Number Extension
  • NullPointerException at BoringLayout.isBoring is anything but boring
  • java.lang.RuntimeException: Unable to get provider
  • Testing custom Views with Robolectric
  • tools:listheader doesn't work although tools:listitem does
  • oppo, vivo app kill notification not coming in android fcm
  • OnClick Method could not function correctly with if else statement
  • Best method to download image from url in Android
  • How can I open Drawer Layout moving all the view and not just slide over?
  • how to show profile pictures of friends in a list view?
  • Creating TimePickerDialog with custom style in Android
  • Android 2.3.6 support library v7 option menu is missing
  • need of vblank in Display subssytem
  • Android MP4 stream - Video cannot be played
  • FastAdapter: Undo button does not show up after swipe
  • What are reasons to pass getActivity as the LifecycleOwner to the LiveData's observe method in a fragment?
  • Implement Face Recognition in Android
  • Titanium studio cannot run "titanium" command in terminal
  • How to execute command line ffmpeg commands programatically in android?
  • Make Android List Items clickable with each item pointing to a different link
  • listview runs successfully, but nothing is display in emulator
  • How to zoom in a bitmap with high resolution?
  • Passing listView data through intent
  • Google map route direction show by arrows in android v2
  • how to start "uiautomator test run" from android code?
  • Proguard in Android Library
  • Alarm Clock from GIT - Gives error - Android
  • Mock injection using Mockito - Android
  • Get Bitmap from universal image loader
  • Unable to include custom font in android
  • Basics on using logcat in Android development
  • Android: Clear cache programmatically
  • Android: pass object without serialization
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org