【发布时间】:2020-03-25 03:23:27
【问题描述】:
当我点击注册按钮时,我需要使用数据绑定获取 SwitchCompat 的已检查状态。
下面是代码
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/switchSymbols"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isChecked="@={myCustomModel.upperCase}"
android:text="" />
在 MyCustomModel 类中
var upperCase: Boolean
@Bindable get() = _isUpperCase
set(value){
_isUpperCase = value
notifyPropertyChanged(BR.upperCase)
}
现在我想使用以下代码获取状态
var isUpperCase = myCustomModel.upperCase
我收到以下错误
Cannot find a getter for <androidx.appcompat.widget.SwitchCompat android:isChecked> that accepts parameter type 'boolean'
If a binding adapter provides the getter, check that the adapter is annotated correctly and that the parameter type matches.
谁能帮我解决这个问题?如何查看 SwitchCompat 的状态?
【问题讨论】:
标签: android kotlin data-binding