尝试在kotlin中打开alertDialog,对话框需要显示标题和一些短信以及一些单选按钮列表。
使对话框部分工作,但无法设置消息(正文),如果设置了消息,则单选按钮将不会显示(???)。
我想这可能是alertDialog的限制,或者有人知道如何解决?
fun openAlertDialog(title: String, alertMessage: String, items: ArrayList<String>) {
val poistion = 0
val alertDilogBuilder = AlertDialog.Builder(activity, R.style.myDialogeTheme)
alertDilogBuilder.setTitle(title)
//alertDilogBuilder.setMessage(alertMessage) //<== if setMessage the radio button will not show
.setSingleChoiceItems(list, poistion, object : DialogInterface.OnClickListener {
override fun onClick(dialog: DialogInterface, index: Int) {
onSelectedCategory(items[index])
Toast.makeText(activity.applicationContext,
items[index],
Toast.LENGTH_SHORT).show()
dialog.dismiss()
}
})
alertDialog = alertDilogBuilder.create()
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, “Ok", {
dialogInterface, i ->
onSelectedCategory(items[0])
})
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "Cancel", {
dialogInterface, k ->
dialogInterface.dismiss()
})
alertDialog!!.show()
}