[英]Catch dialog close event from caller class
我有一個自定義對話框。 如何從調用對話框的 class 捕獲對話框關閉事件?
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
}
我需要從 kotlin 和 Java 類中捕獲此事件。
在你的function中創建一個回調參數,在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
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.