Vervatovskis
Vervatovskis

Reputation: 2367

Intercept the menu click

how could i intercept the click on the menu button of the device (phone for example). I need something like OnMenuClick().

Upvotes: 4

Views: 1272

Answers (4)

Vervatovskis
Vervatovskis

Reputation: 2367

I solve it my self, like this

@Override
public boolean onKeyDown(int keyCode, KeyEvent event)  {

    if ((keyCode == KeyEvent.KEYCODE_MENU||keyCode == KeyEvent.KEYCODE_BACK) && event.getRepeatCount() == 0) {

        // my code here...        
    }
}

Upvotes: 3

Ahmed Salem
Ahmed Salem

Reputation: 3969

implement

onPrepareOptionsMenu(Menu menu)

it gets called every time the menu button is clicked

Upvotes: 0

Vinay
Vinay

Reputation: 2415

You need to implement 2 things.

  1. onCreateOptionsMenu()
  2. onOptionMenuItemClick().

All click events will come to 2.

Sample is here.

Upvotes: 0

vicentazo
vicentazo

Reputation: 1799

You can to handle when the menu is opened with onMenuOpened()

Upvotes: 0

Related Questions