Android: How to override onBackPressed() in AlertDialog?

后端 未结 4 1400
[愿得一人]
[愿得一人] 2021-02-05 04:30

I have an AlertDialog dlgDetails which is shown from another AlertDialog dlgMenu. I would like to be able to show dlgMenu again if the user presses the

4条回答
  •  情书的邮戳
    2021-02-05 05:07

    This handles both the BACK button and the click OUTSIDE the dialog:

    yourBuilder.setOnCancelListener(new OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            dialog.cancel();
            // do your stuff...
        }
    });
    

    dialog.cancel() is the key: with dialog.dismiss() this would handle only the click outside of the dialog, as answered above.

提交回复
热议问题