views:

50

answers:

1

I am implementing a context menu for my main activity. I have some XML to define the items:

<menu xmlns:android="http://schemas.android.com/apk/res/android"&gt;
<item   
android:title="@string/random_item"
android:id="@+id/random_item"
android:icon="@drawable/random"/>
<item   
android:title="@string/about_item"
android:id="@+id/about_item"
android:icon="@android:drawable/ic_menu_info_details"/>
</menu>

I have this code to create the menu:

@Override public boolean onCreateOptionsMenu(Menu menu)
{
    getMenuInflater().inflate(R.menu.main, menu);
    return (super.onCreateOptionsMenu(menu));
}

And I have implemented onContextItemSelected to get my callbacks:

@Override public boolean onContextItemSelected (MenuItem item)
{
    // do some stuff 
}

When I click the menu button, my context menu appears with the appropriate items and icons. When I select a menu item, I don't get the callback. What am I missing here?

+2  A: 

Instead of onContextItemSelected you have to override onOptionsItemSelected, method that you use is related to context menu (usually appears after long press events) not to the options menu.

Konstantin Burov
(face palm) Thanks :)
Cannonade