Say I have a created a dialog in my Android app like so:
private static ProgressDialog dialog;
dialog = ProgressDialog.show(MainActivity.this, \"\", \"Downlo
Sure you can - check:
public void onDismiss(DialogInterface dialogInterface)
{
//Fire event
}
Use setOnDismissListener method for the dialog.
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
if (mIsSettingsDirty)
refreshRecyclerView();
}
});
Use an OnDismissListener.
There is a setOnDismissListener(...) method in the class Dialog
If you want handle Dialog
hiding, you can override 2 methods.
@Override
public void cancel() {
super.cancel();
callback();
}
@Override
public void dismiss() {
super.dismiss();
callback();
}
If you are within custom dialog class - override dismiss(). I recommend inserting logic BEFORE super.dismiss(). Kotlin example:
override fun dismiss() {
Utils.hideKeyboard(mContext, window)
super.dismiss()
}
Whenever a dialog is closed either by clicking PositiveButton, NegativeButton, NeturalButton or by clicking outside of the dialog, "onDismiss" is always gets called automatically so do your stuff inside the onDismiss() method e.g.,
@Override
public void onDismiss(DialogInterface dialogInterface) {
...
}
You don't even need to call dismiss() method.