Reputation: 3
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.
Upvotes: 0
Views: 1610
Reputation: 11
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
Upvotes: 1
Reputation: 789
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.
}
Upvotes: 1