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);
}
call this method in
onMenuItemSelected(int featureId, MenuItem item)rather thanonContextItemSelected(MenuItem item), OptionMenu and ContextMenu are two different type menus in android