I’m trying to rewrite hardver menu button to show a sub menu on click.
I’m using the ActionBarSherlock.
so I have the following code:
@Override
public boolean onKeyDown(int keycode, KeyEvent e) {
if (keycode == KeyEvent.KEYCODE_MENU && this._menu != null
&& this._menu.findItem(R.id.menu_button) != null) {
this._menu.performIdentifierAction(R.id.menu_button,
0);
return true;
}
return super.onKeyDown(keycode, e);
}
where R.id.menu_button is the sub menu that I need to open.
On click on the menu button, the submenu opens but when I release the hardver menu button, the option menu closes. How to make the option menu to change the state from close to shown and form shown to close on the press of the hardver menu button and retain the state when the button is released?
Try to use
onKeyUp()instead ofonKeyDown().