user7437908
user7437908

Reputation:

How to perform an action when a customer dialog box is closed in Android Studio?

I am changing a text of a label when the dialog box opens via a button click, what I also want to do is change the text back when the dialog box closes. I do not have any buttons on the dialog and by default user is able to press the back key or tap anywhere outside of the dialog box to close it. (I do not want to add a button). I have been trying for to work this out for a good day now and still for the life of me figure out how it works (Shows what a newbie I am!) I have tried various methods e.g.

  1. if(dialog.isShowing() != true) label2.setText = "Well done"

but none seems to work, I understand the solution may be simple... I have tried stuff like dismiss etc. too.

I will really appreciate if someone could shed some light on this.

Upvotes: 0

Views: 748

Answers (2)

MuTiny
MuTiny

Reputation: 257

You can use an onDismissListener() to set as listener whenever the dialog is closed

Upvotes: 0

Martin De Simone
Martin De Simone

Reputation: 2148

    Customdialog=new Dialog(this);
    Customdialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialogInterface) {
        //code you want to execute when the dialog is closed 
        }
    });

Hope it helps (:

Upvotes: 1

Related Questions