Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get menu group id in Android?

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);
}
like image 395
Kris B Avatar asked Apr 12 '12 01:04

Kris B


People also ask

How do I access menu items on Android?

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.

What is ifRoom in Android?

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.

What is Android system menu?

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.

What is context menu Android?

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.


1 Answers

call this method in onMenuItemSelected(int featureId, MenuItem item) rather than onContextItemSelected(MenuItem item), OptionMenu and ContextMenu are two different type menus in android

like image 52
Longerian Avatar answered Sep 28 '22 18:09

Longerian