简体   繁体   English

找不到属性“ android:checked”的吸气剂

[英]Cannot find the getter for attribute 'android:checked'

data binding error ****msg:Cannot find the getter for attribute 'android:checked' with value type java.lang.Boolean on android.widget.CheckedTextView. 数据绑定错误**** msg:在android.widget.CheckedTextView上找不到类型为java.lang.Boolean的属性'android:checked'的获取方法。

I have a Kotlin Android app and one of the XML layouts contains a CheckedTextView and I want to two-way bind the checked property to the checked value of the ViewModel. 我有一个Kotlin Android应用程序,其中一个XML布局包含一个CheckedTextView并且我想将选中的属性双向绑定到ViewModel的选中值。 The idea is that the checked property in the viewModel will represent the one on the view itself. 这个想法是viewModel中的checked属性将代表视图本身上的属性。 This fails with the error message above. 这将失败,并显示以上错误消息。 Now I wonder whether this is because checked is a boolean value and the getter is called isChecked . 现在我想知道这是否是因为check是一个布尔值,而该getter称为isChecked Can Databinding not recognize that? 数据绑定无法识别吗? So I tried extending it with a getChecked function, but that didn't resolve the error. 因此,我尝试使用getChecked函数对其进行getChecked ,但是并不能解决该错误。 Maybe because while Kotlin supports extension functions, Java does not. 可能是因为虽然Kotlin支持扩展功能,但Java不支持。 Any ideas how this can be solved? 有什么想法可以解决吗?

XML file: XML档案:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
    <data>
        <variable name="viewModel"
            type="lehrbaum.de.onenightcomps.view.SimpleCheckableListItemViewModel"/>
    </data>
    <CheckedTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textView"
        android:padding="@dimen/text_margin"
        android:gravity="center_vertical"
        android:textStyle="bold"
        android:checkMark="?android:attr/listChoiceIndicatorSingle"
        android:checkMarkTint="@color/colorPrimary"
        android:checked="@={viewModel.checked}"
        android:text="@{viewModel.text}"/>
</layout>

ViewModel class: ViewModel类:

class SimpleCheckableListItemViewModel {
    val checked : MutableLiveData<Boolean> = MutableLiveData()
    val text : MutableLiveData<String> = MutableLiveData()
}

Extension function: 扩展功能:

fun CheckedTextView.getChecked(): Boolean {
    return this.isChecked
}

There might be different reasons for this error but in my case, the problem raised up because I didn't add apply plugin: 'kotlin-kapt' And apply plugin: 'kotlin-android-extensions' in my Gradle. 发生此错误的原因可能不同,但就我而言,问题是由于我没有在Gradle中添加Apply插件:'kotlin-kapt'和应用插件:'kotlin-android-extensions'而引起的。

After adding these plugins you have to replaced your annotationProcessors with kapt. 添加这些插件后,您必须用kapt替换您的注解处理器。

After that, every thing might be going well. 在那之后,所有事情可能都会进展顺利。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到属性“ android:tag”的获取器-Android - Cannot find the getter for attribute 'android:tag' - Android Android:找不到符号类 DataBinderMapperImpl。 找不到 android:state_checked 的吸气剂 - Android: Cannot find symbol class DataBinderMapperImpl. Cannot find a getter for android:state_checked Android数据绑定-找不到属性的获取器 - Android Data-binding - Cannot find the getter for attribute 找不到属性&#39;android:text&#39;的getter,值类型为java.lang.String,返回null - Cannot find the getter for attribute 'android:text' with value type java.lang.String on null msg:在数据绑定中找不到值为java.lang.String的属性&#39;android:text&#39;的getter? - msg:Cannot find the getter for attribute 'android:text' with value type java.lang.String in data binding? 错误:在 Android Room 中找不到字段的 getter - error: Cannot find getter for field in Android Room 在 kotlin 中使用数据绑定时找不到属性 ImageView 的 getter - Cannot find the getter for attribute ImageView while using Databinding in kotlin 找不到值类型为布尔值的属性“app:vm”的 GETTER - Cannot find the GETTER for attribute 'app:vm' with value type Boolean 如何解决:“在使用自定义视图实现双向数据绑定时,找不到属性&#39;android:text&#39;”的getter? - How to solve: “cannot find getter for attribute 'android:text'” when implementing two-way data binding with custom view? 找不到字段的吸气剂 - Cannot find getter for field
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM