使用警报对话框编辑文本时出现奇怪的输出
Weird output on edit text with alert Dialog
Weird output
当我输入文本时,我在警告对话框中得到了这个输出。
有人可以解释为什么会这样吗。
logcat 中没有错误。
这是我的警报对话框代码
private fun declineDialogBox() {
val dialogBuilder = AlertDialog.Builder(this)
val inflater = layoutInflater
val dialogLayout = inflater.inflate(R.layout.alert_dialog, null)
val toBeCorrected = dialogLayout.findViewById<EditText>(R.id.editText)
dialogBuilder.setMessage("Reason is?")
.setCancelable(false)
.setPositiveButton("Proceed") { dialog, id ->
finish()
Toast.makeText(applicationContext, "Reason is $toBeCorrected", Toast.LENGTH_SHORT)
.show()
}
.setNegativeButton("Cancel") { dialog, id ->
}
val alert = dialogBuilder.create()
alert.setView(dialogLayout)
alert.setTitle("To Be Corrected")
alert.show()
}
您正在打印 EditText
的实例而不是 value
,添加 .text
以从 EditText
获取值
Toast.makeText(applicationContext, "Reason is ${toBeCorrected.text}", Toast.LENGTH_SHORT).show()
Weird output
当我输入文本时,我在警告对话框中得到了这个输出。
有人可以解释为什么会这样吗。
logcat 中没有错误。
这是我的警报对话框代码
private fun declineDialogBox() {
val dialogBuilder = AlertDialog.Builder(this)
val inflater = layoutInflater
val dialogLayout = inflater.inflate(R.layout.alert_dialog, null)
val toBeCorrected = dialogLayout.findViewById<EditText>(R.id.editText)
dialogBuilder.setMessage("Reason is?")
.setCancelable(false)
.setPositiveButton("Proceed") { dialog, id ->
finish()
Toast.makeText(applicationContext, "Reason is $toBeCorrected", Toast.LENGTH_SHORT)
.show()
}
.setNegativeButton("Cancel") { dialog, id ->
}
val alert = dialogBuilder.create()
alert.setView(dialogLayout)
alert.setTitle("To Be Corrected")
alert.show()
}
您正在打印 EditText
的实例而不是 value
,添加 .text
以从 EditText
Toast.makeText(applicationContext, "Reason is ${toBeCorrected.text}", Toast.LENGTH_SHORT).show()