问题描述
如果某些属性,即 has_tv 为空,或者换句话说,用户已将 RadioGroup 留空,我似乎无法解决这个想法,我如何使用数据绑定和 MVVM 请求关注该特定视图,任何帮助是赞赏
XML
<RadioGroup
android:id="@+id/rgHasTv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tvTv"
android:layout_marginHorizontal="20dp"
android:layout_marginTop="5dp"
android:onCheckedChanged="@{(radioGroup,checkedId) -> viewmodel.setTv(radioGroup,checkedId)}"
android:orientation="vertical"
android:tooltipText="">
<RadioButton
android:id="@+id/tv_yes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Yes"
android:textSize="16dp" />
<RadioButton
android:id="@+id/tv_no"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="No"
android:textSize="16dp" />
</RadioGroup>
科特林
fun setTv(radioGroup: RadioGroup,checkedId: Int) {
if (checkedId == R.id.tv_yes) {
Log.d("Checked: ","TV YES");
household.has_tv = "1";
}
if (checkedId == R.id.tv_no) {
Log.d("Checked: ","TV NO");
household.has_tv = "2";
}
radioGroup.requestFocus()
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)