gpt4 book ai didi

kotlin - 如何处理对话框中的取消和确定按钮

转载 作者:行者123 更新时间:2023-12-02 13:29:44 24 4
gpt4 key购买 nike

当我单击确定按钮时,我想要的是它执行某些操作的对话框,与取消按钮相同

覆盖
有趣的 onCreateDialog(savedInstanceState: Bundle?): Dialog {

    val builder = AlertDialog.Builder(this.requireActivity())

// Dialog will have "Make a selection" as the title
builder.setMessage("Details successfully captured.Do you wish to proceed and book your seat?")
// An OK button that does nothing
.setPositiveButton("OK") { dialog, id ->
// Nothing happening here

}
// A "Cancel" button that does nothing
.setNegativeButton("Cancel") { dialog, id ->
// Nothing happening here either
}

最佳答案

 val builder = AlertDialog.Builder(this)
.setMessage("Yes or No")
.setPositiveButton("OK"){ dialogInterface: DialogInterface, i: Int ->
Toast.makeText(this,"Ok Pressed",Toast.LENGTH_LONG).show()
dialogInterface.dismiss()
}
.setNegativeButton("No"){ dialogInterface: DialogInterface, i: Int ->
Toast.makeText(this,"No Pressed", Toast.LENGTH_SHORT).show()
dialogInterface.dismiss()
}

DialogInterface.OnClickListener 有两个参数:-

对话框 -> 接收点击的对话框
i -> 点击项目的位置

像上面的 toast 一样编写执行逻辑,最后可以使用可用的对话框来关闭。

关于kotlin - 如何处理对话框中的取消和确定按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62134267/

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