Pergunta

I created a popupwindow to show a menu. I found that if I press the cancel button on keyboard, the popupwindow will dismiss, and setFocusable() only disable the buttons like menu, but cancel button still works. If there exists a method to make popupwindow invalid for popupwindow, or define the action myself when a cancel button is pressed? Thanks.

Well I mean back button when i say cancel button. And Thanks for sachy and other people who reply me.

Foi útil?

Solução

By cancel button do you mean back button? If yes than u can simply override onKeyDown().

 @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK)) {
        Log.d("back", "back button pressed");
    }
    return true; //to prevent this event from being propagated further.
}

Outras dicas

Please explain more to now exactly what you want to achieve. If you just want to disable the button you might try this.

Button button = (Button)findViewById(R.id.button1);
button.setEnabled(false);

Or you want to override the cancel button? Check this out then: Back button behavior

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top