【发布时间】:2018-10-31 22:39:56
【问题描述】:
我在RadioGroup 中有一个动态添加的单选按钮。而且我必须根据一些数据在代码中检查其中一个。
现在,问题是在显示单选按钮并且用户检查同一组中的另一个单选按钮后,之前选择的单选按钮仍处于选中状态...导致两个选中的RadioButtons。
这就是我在 Kotlin 中渲染按钮的方式:
val rg = RadioGroup(this).apply { orientation = RadioGroup.HORIZONTAL }
choices.values.forEach { c ->
rg.addView(RadioButton(this).apply {
tag = someTag
text = c
isChecked = answer.equals(c) // condition
})
}
奇怪的是,如果没有以编程方式检查 RadioButton,一切正常。
【问题讨论】:
-
你在使用 kotlin-kapt 插件吗? (只是为了让我知道在我的答案中使用什么)
-
@AnthonyCannon 没有。只是普通的 kotlin。
标签: android kotlin radio-button