Can you fire an event when Android Dialog is dismissed?

前端 未结 6 1112
一整个雨季
一整个雨季 2020-12-11 00:33

Say I have a created a dialog in my Android app like so:

private static ProgressDialog dialog;
dialog = ProgressDialog.show(MainActivity.this, \"\", \"Downlo         


        
相关标签:
6条回答
  • 2020-12-11 00:41

    Sure you can - check:

      public void onDismiss(DialogInterface dialogInterface)
      {
            //Fire event
      }
    
    0 讨论(0)
  • 2020-12-11 00:43

    Use setOnDismissListener method for the dialog.

    dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            if (mIsSettingsDirty)
                refreshRecyclerView();
        }
    });
    
    0 讨论(0)
  • 2020-12-11 00:54

    Use an OnDismissListener.

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

    0 讨论(0)
  • 2020-12-11 00:55

    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();
        }
    
    0 讨论(0)
  • 2020-12-11 01:01

    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()
    }
    
    0 讨论(0)
  • 2020-12-11 01:06

    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.

    0 讨论(0)
提交回复
热议问题