Home > Blockchain >  Catch dialog close event from caller class
Catch dialog close event from caller class

Time:11-30

I have a custom dialog. How can I catch dialog close event from class which call dialog?

class DialogShow {
    companion object {
    fun showDialog() {
      //some logic
      val customDialog = CustomDialog(account, context)
      customDialog.onDismissListener = {
           // here I need to return close event
      }
      customDialog.show(activity,"rawer")
    }
    

 }
}

calss CallDialog{
  DialogShow.showDialog()
  //here I need to catch dialog dismiss
}

I need to catch this event from kotlin and Java classes.

CodePudding user response:

Create a callback parameter in your function, and call it in the onDismissListener:

class DialogShow {
  companion object {
    fun showDialog(context: Context, onDismiss: ()->Unit) {
      //some logic
      val customDialog = CustomDialog(account, context)
      customDialog.onDismissListener = {
           onDismiss()
      }
      customDialog.show(context, "rawer")
    }
  }
}

fun foo() {
  DialogShow.showDialog(context) {
    // code that is run after dialog is closed
  }
}
  • Related