android-radiogroup - radioGroup.setOnCheckedChangeListener 给出不兼容的类型:RadioButton 和 Int
问题描述
我正在学习有趣的 Kotlin、Android Studio 和 viewBinding。这对我来说是麻烦的开始。我怎样才能使这个代码工作?
binding.radioGroup.setOnCheckedChangeListener { group, checkedId ->
val rbtn: RadioButton = radioGroup.findViewById<RadioButton>(checkedId)
when (rbtn.id) {
binding.radioButton1 ->
Toast (...)
binding.radioButton2 ->
Toast (...)
binding.radioButton3 ->
Toast (...)
binding.radioButton4 ->
Toast (...)
}
}
binding.radioButton1(或任何其他)给出不兼容的类型:RadioButton 和 Int 错误。
解决方案
推荐阅读
- sql - 为什么插入到具有主键/标识列的表中会生成“列名或提供的值的数量与表定义不匹配”错误
- xml - 具有多个命名空间的 XML 解析
- php - WordPress帖子数:Y中的X?
- gradle - Gradle 自定义任务实现:找不到参数的方法
- android - 软件键盘打开时调整图像大小
- javascript - Chrome 中的高精度 FPS 测量
- python - 如何使用 selenium python 上传图像?
- javascript - 有没有一种方法可以仅使用 javascript 合并表中的某些列
- r - gsub 包含特殊字符的字符串
- python - 将每个子列表乘以一个常数