How to know if a dialog is dismissed in Android?

后端 未结 4 1656
面向向阳花
面向向阳花 2020-12-29 19:43

If the dialog is dismissed,I want to do something for my background.So I want to know if the dialog is dismissed

4条回答
  •  既然无缘
    2020-12-29 20:31

    @Ken Wolf has a great answer to this question.

    Just wanted to add that onDismissListener was only introduced in API 17. If you are trying to support something lower, you can use onCancelListener, which is not as good but covers cases like backButton and tapping outside of the AlertDialog.

    http://developer.android.com/reference/android/content/DialogInterface.OnCancelListener.html#onCancel(android.content.DialogInterface)

    public Dialog createDialog() {
        Dialog d = new Dialog(this);
        d.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                // do something
            }
        });
    }
    

提交回复
热议问题