AlertDialog how to handle click outside of dialog view

Viewed 2119

I have AlertDialog and there are some buttons. By clicking them, some function/method begin to work.

But what to do if user clicks outside of AlertDialog view?

I want to start specific function then user clicks at empty field (outside of dialog view)

enter image description here

1 Answers

You have to use this -

dialog.setCanceledOnTouchOutside(true);

Then for executing your function on outside click of dialog, do like this -

dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
    @Override
    public void onCancel(DialogInterface dialog) {
        // dialog dismisses
        // Do your function here
    }
});
Related