我在互联网上大量搜索了我如何使用 Kotlin 在 android 上使用setFocusable()
,setText()
等setError()
方法editText(s)
(我知道我们可以在 java 中使用上述方法),但我无法找到适用的确切解决方案我。
我正在使用 1.) 用于 http 调用的 Volley 2.) 用于 android studio 的 kotlin 插件,版本 = '1.1.3-2' 3.) anko 库
应用程序运行时我面临的问题: 1.) setError() 方法没有被调用。2.) 我无法在 editText 上使用 setText() 和 setFocus()。
请注意,我需要 Kotlin 而不是 Java 中的解决方案。
提前致谢!
private fun askAppointment() {
if (editTextPersonName?.text.isNullOrEmpty()) {
editTextPersonName?.error ="Person Name cannot be empty."
return
} else if (editTextPersonMobile?.text.isNullOrEmpty()) {
editTextPersonMobile?.error = "Person Mobile cannot be empty."
return
} else if (editTextPersonEmail?.text.isNullOrEmpty()) {
editTextPersonEmail?.error = "Person Email cannot be empty."
return
} else if (editTextSubject?.text.isNullOrEmpty()) {
editTextSubject?.error = "Subject cannot be empty."
return
} else if (editTextDescription?.text.isNullOrEmpty()) {
editTextDescription?.error = "Description cannot be empty."
return
} else if (editTextAppointmentDate?.text.isNullOrEmpty()) {
editTextAppointmentDate?.error = "Appointment Date cannot be empty."
return
} else if (editTextAppointmentTime?.text.isNullOrEmpty()) {
editTextAppointmentTime?.error = "Appointment Time cannot be empty."
return
}