【问题标题】:How to get checked status of SwitchCompat using Databinding in Android如何在 Android 中使用数据绑定获取 SwitchCompat 的检查状态
【发布时间】: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


    【解决方案1】:

    我认为应该检查而不是isChecked?

    android:checked="@={@={myCustomModel.upperCase}}"
    

    【讨论】:

    • 是的,这是我的错误。我意识到并修复了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-08
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    • 2020-11-07
    • 1970-01-01
    相关资源
    最近更新 更多