Can you fire an event when Android Dialog is dismissed?

牧云@^-^@ 提交于 2019-11-29 09:03:49
Aleadam

Use an OnDismissListener.

There is a setOnDismissListener(...) method in the class Dialog

Sure you can - check:

  public void onDismiss(DialogInterface dialogInterface)
  {
        //Fire event
  }

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.

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()
}

Use setOnDismissListener method for the dialog.

dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
    @Override
    public void onDismiss(DialogInterface dialog) {
        if (mIsSettingsDirty)
            refreshRecyclerView();
    }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!