Android 如何在多个按钮单击时更改对话框中文本视图的文本?使用kotlin

Android 如何在多个按钮单击时更改对话框中文本视图的文本?使用kotlin,android,kotlin,android-alertdialog,Android,Kotlin,Android Alertdialog,我想我有两个按钮。 我需要打开按钮点击对话框。 当按钮1单击时,一些文本显示,当按钮2单击时,其他文本显示为对话框 我的代码 btn1.setOnClickListener{ showCustomDialog() } btn2.setOnClickListener{ showCustomDialog() } private-lateinit-var-alertDialog:alertDialog 趣味showCustomDialog(){ val充气机:LayoutInflater=this.

我想我有两个按钮。 我需要打开按钮点击对话框。 当按钮1单击时,一些文本显示,当按钮2单击时,其他文本显示为对话框

我的代码

btn1.setOnClickListener{ showCustomDialog() }
btn2.setOnClickListener{ showCustomDialog() }
private-lateinit-var-alertDialog:alertDialog
趣味showCustomDialog(){
val充气机:LayoutInflater=this.getLayoutInflater()
val对话框视图:视图=充气机。充气(R.layout.dialog\u custom\u视图,空)
val headerbtn=dialogView.findviewbyd(R.id.header)
headerbtn.text=“标题消息”
val dialogBuilder:AlertDialog.Builder=AlertDialog.Builder(上下文!!)
dialogBuilder.setOnDismissListener(对象:DialogInterface.OnDismissListener{
重写命令(arg0:DialogInterface){
}
})
dialogBuilder.setView(dialogView)
alertDialog=dialogBuilder.create();
alertDialog.window!!.getAttributes().windowAnimations=R.style.PauseDialog组织
alertDialog.show()
}

将字符串发送到函数,然后将其放在TextView上

btn1.setOnClickListener{ showCustomDialog("This is Text 1") }
btn2.setOnClickListener{ showCustomDialog("This is Text 2") }
功能:

fun showCustomDialog(data: String) {
    val inflater: LayoutInflater = this.getLayoutInflater()
    val dialogView: View = inflater.inflate(R.layout.dialog_custom_view, null)

    val headerbtn = dialogView.findViewById<TextView>(R.id.header)
    headerbtn.text = data

    val dialogBuilder: AlertDialog.Builder = AlertDialog.Builder(context!!)
    dialogBuilder.setOnDismissListener(object : DialogInterface.OnDismissListener {
        override fun onDismiss(arg0: DialogInterface) {

        }
    })
    dialogBuilder.setView(dialogView)

    alertDialog = dialogBuilder.create();
    alertDialog.window!!.getAttributes().windowAnimations = R.style.PauseDialogAnimation
    alertDialog.show()
}
fun showCustomDialog(数据:字符串){
val充气机:LayoutInflater=this.getLayoutInflater()
val对话框视图:视图=充气机。充气(R.layout.dialog\u custom\u视图,空)
val headerbtn=dialogView.findviewbyd(R.id.header)
headerbtn.text=数据
val dialogBuilder:AlertDialog.Builder=AlertDialog.Builder(上下文!!)
dialogBuilder.setOnDismissListener(对象:DialogInterface.OnDismissListener{
重写命令(arg0:DialogInterface){
}
})
dialogBuilder.setView(dialogView)
alertDialog=dialogBuilder.create();
alertDialog.window!!.getAttributes().windowAnimations=R.style.PauseDialog组织
alertDialog.show()
}

您添加了正确的代码吗?我想您忘了在showCustomDialog()中添加参数。您不需要更多帮助。上面没有提到我简化问题的实际要求。当我有两个文本视图时?如何做到这一点?您有两个不同的文本视图,然后需要通过参数提供两个变量。
showDialog(“这是文本1”,“这是文本1.2”)
,然后根据
fun showCustomDialog(数据:字符串,数据1:字符串)
@P.Mohanta工作了?。如果你有空的第二个字符串,那么放?允许为空。
fun showCustomDialog(data: String) {
    val inflater: LayoutInflater = this.getLayoutInflater()
    val dialogView: View = inflater.inflate(R.layout.dialog_custom_view, null)

    val headerbtn = dialogView.findViewById<TextView>(R.id.header)
    headerbtn.text = data

    val dialogBuilder: AlertDialog.Builder = AlertDialog.Builder(context!!)
    dialogBuilder.setOnDismissListener(object : DialogInterface.OnDismissListener {
        override fun onDismiss(arg0: DialogInterface) {

        }
    })
    dialogBuilder.setView(dialogView)

    alertDialog = dialogBuilder.create();
    alertDialog.window!!.getAttributes().windowAnimations = R.style.PauseDialogAnimation
    alertDialog.show()
}