Android: How can I set a listener to the MenuButton?

Usually you shouldn't override MENU behavior as users expect menu to appear, however you can use something along these lines: (non-Javadoc) * @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"); return true; } return super. OnKeyDown(keyCode, event); }.

Usually you shouldn't override MENU behavior as users expect menu to appear, however you can use something along these lines: /* (non-Javadoc) * @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"); return true; } return super. OnKeyDown(keyCode, event); }.

Thanks - this is what I was looking for. And don't worry - I'm not gona change the user experience but I want to do some custom actions before the menu is actually rendered. – Mannaz Mar 22 '10 at 9:34.

But onPrepareOptionsMenu(..) is called each time. :).

1 Not a very long answer, but this is the way to do it! As he said, it's called every time before the menu actually appears, so you can customise your menu in that. – Steve Haley Mar 19 '10 at 15:58.

You could probably hack something in using "OnMenuOpened" or some such, but I really wouldn't recommend it. The menu button is only supposed to be used to show menus, so there is consistency between applications.

OnCreateOptionsMenu is only called the first time the button is pressed - I've already tried this.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions