简体   繁体   中英

Catch dialog close event from caller class

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM