【发布时间】:2017-02-24 05:19:18
【问题描述】:
如何使用数据绑定将我的对象字符串字段值与 xml 文件中的另一个字符串值进行比较?是否可以在 xml 文件中这样做,或者我应该在我的项目中的某处使用 @BindingAdapter 注释创建一个方法?
以下是我迄今为止尝试过的,但没有奏效。与字符串资源值进行比较而不是与硬编码的字符串值进行比较也会很好。
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/male"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="@{user.gender.equalsIgnoreCase("male")}"
android:text="@string/male"/>
<RadioButton
android:id="@+id/female"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="@{user.gender.equalsIgnoreCase("female")}"
android:text="@string/female"/>
</RadioGroup>
感谢您的帮助。
【问题讨论】:
标签: android data-binding android-databinding