在我的布局中,我有一个复选框,它应该切换不同 View 的启用状态。这意味着,一个 View 的选中值应该绑定(bind)到不同 View 的启用值。
对我来说,这听起来像是新数据绑定(bind)库的完美用例,在我看来,它应该是 xml 中的简单行,而不必使用 Java 代码。像 android:enabled="@{(@id/chk_enabled).isChecked()}"
我在想。遗憾的是,这是无效的,而且我找不到有关如何正确执行此操作的任何信息。
这就是为什么我想知道,这可能吗?
最佳答案
试试这个:
<CheckBox
android:id="@+id/showMore"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<EditText
android:enabled="@{showMore.checked ?true:false}"
android:layout_width="match_parent"
android:layout_height="20dp" />
关于android - 没有java代码的数据绑定(bind): View to view binding,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40019345/