I have refer many article but I am not getting that "if any user click on menu button of mobile then it will display only option menu not context menu ... If there is another way to show the context menu by clicking on menu button on mobile then suggest me.
Asked
Active
Viewed 520 times
0
-
If I understand your question simply override the longClickListener, for the items that should have a ContextMenu. – Sam Jun 08 '12 at 18:29
-
no sam i want that when user click on menu button (which is already present in mobile )then it show context menu . – Ashishsingh Jun 08 '12 at 18:34
-
1I think this is what ur r searching for : http://stackoverflow.com/questions/2478418/android-how-can-i-set-a-listener-to-the-menubutton/2478556#2478556 – Chanchal Shelar Jun 09 '12 at 08:50
2 Answers
1
My be following link is what you are looking for : Android: How can I set a listener to the MenuButton?
i.e.
Usually you shouldn't override MENU
behavior as users expect menu to appear, however you can use something along these lines:
/*
* @see android.app.Activity#onKeyDown(int, android.view.KeyEvent)
*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ( keyCode == KeyEvent.KEYCODE_MENU ) {
Log.d(TAG, "MENU pressed");
// Your context opening code....
return true;
}
return super.onKeyDown(keyCode, event);
}

Community
- 1
- 1

Chanchal Shelar
- 363
- 2
- 12
0
Beginning with Android 3.0 (API level 11), Android-powered devices are no longer required to provide a dedicated Menu button.
From the documentation
So while I would advise against this, here is one approach to what your question.
When you want to display a ContextMenu instead of your Options Menu, add a command like this in onPrepareOptionsMenu()
:
openContextMenu(getCurrentFocus());

Sam
- 86,580
- 20
- 181
- 179