gpt4 book ai didi

android - Kotlin/Anko 防止按钮关闭警报对话框

转载 作者:行者123 更新时间:2023-12-03 02:43:11 25 4
gpt4 key购买 nike

当在 Anko 的警报生成器中使用 positiveButtonnegativeButton 时,即使 dismiss() ,它们似乎都会导致关闭对话框不被调用。有什么方法可以在单击按钮后保持对话框打开(如果有 positiveButton/negativeButton 以外的类型,也可以)?

alert {
title = "Add Board"
customView {
....
}
positiveButton("OK") { doSomeFunction() }
negativeButton("Close"){}
}.show()

最佳答案

对于将来可能遇到此问题的任何人,这就是在 Kotlin 中实现此问题的方法

val myAlert = alert {
title = "Add Board"
customView {
....
}
positiveButton("OK") { /*Keep blank, we'll override it later*/}
negativeButton("Close"){}
}.show()

//You can use BUTTON_NEGATIVE and BUTTON_NEUTRAL for other buttons
(myAlert as AlertDialog).getButton(AlertDialog.BUTTON_POSITIVE)
.setOnclickListener{
doSomeFunction()
}

关于android - Kotlin/Anko 防止按钮关闭警报对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45696083/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com