Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know if a dialog is dismissed in Android?

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

like image 850
Marshal Chen Avatar asked Jul 09 '13 09:07

Marshal Chen


People also ask

How do I know if my dialog is dismissed android?

For me onCancelListener was the best option since I needed something that tracked an explicit closing of the dialog by clicking outside the alert area. Show activity on this post. When dialog closed, you can use dialog. setOnDismissListener at the following code with the usage of an updated dialog code.

How do you dismiss a DialogFragment?

tl;dr: The correct way to close a DialogFragment is to use dismiss() directly on the DialogFragment. Control of the dialog (deciding when to show, hide, dismiss it) should be done through the API here, not with direct calls on the dialog. Dismiss the fragment and its dialog.


1 Answers

You can use an onDismissListener

http://developer.android.com/reference/android/content/DialogInterface.OnDismissListener.html

public Dialog createDialog() {     Dialog d = new Dialog(this);     d.setOnDismissListener(new OnDismissListener() {         @Override         public void onDismiss(final DialogInterface arg0) {             // do something         }     });     return d; } 

If you are using a DialogFragment just override onDismiss()

http://developer.android.com/reference/android/app/DialogFragment.html#onDismiss(android.content.DialogInterface)

like image 81
Ken Wolf Avatar answered Sep 19 '22 11:09

Ken Wolf