How do I fire an event when click occurs outside a dialog

When dialog.setCanceledOnTouchOutside(true); then you just override onCancel() like this:

dialog.setOnCancelListener(
        new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                //When you touch outside of dialog bounds, 
                //the dialog gets canceled and this method executes.
            }
        }
);

Type your code inside the onCancel() method so it runs when the dialog gets canceled.

Leave a Comment