Is it possible to get the group id that a menu item is in?
I thought this would work, but getGroupId()
always returns 0:
xml:
<?xml version="1.0" encoding="UTF-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:id="@+id/menu_group">
<item android:id="@+id/edit"
android:title="Edit" />
<item android:id="@+id/delete"
android:title="Delete" />
</group>
</menu>
code:
@Override
public boolean onContextItemSelected(MenuItem item) {
int groupId = item.getGroupId(); //always zero
return super.onContextItemSelected(item);
}
you can access the MenuItem with the id menuItemPinQuote like this in your Android/Java code: public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) { menuInflater. inflate(R. menu.
ifRoom. Only place this item in the app bar if there is room for it. If there is not room for all the items marked "ifRoom" , the items with the lowest orderInCategory values are displayed as actions, and the remaining items are displayed in the overflow menu. withText.
The Android System Settings menu allows you to control most aspects of your device—everything from establishing a new Wi-Fi or Bluetooth connection, to installing a third-party onscreen keyboard, to adjusting system sounds and screen brightness.
In Android, the context menu is like a floating menu and arises when the user has long pressed or clicks on an item and is beneficial for implementing functions that define the specific content or reference frame effect. The Android context menu is alike to the right-click menu in Windows or Linux.
call this method in onMenuItemSelected(int featureId, MenuItem item)
rather than onContextItemSelected(MenuItem item)
, OptionMenu and ContextMenu are two different type menus in android
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With