简体   繁体   English

Android数据绑定BindingAdapter:“找不到设置器”

[英]Android Data Binding BindingAdapter: “Cannot find the setter”

This bound attribute is failing to build, with the error: 此绑定属性无法构建,并显示以下错误:

Cannot find the setter for attribute "errorText" 找不到属性“ errorText”的设置器

@BindingAdapter({"errorText"})
public static void setErrorText(TextInputLayout view, String error) {
    view.setError(error);
}


    <android.support.design.widget.TextInputLayout
        android:id="@+id/email_layout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:errorEnabled="true"
        app:errorText="@{data.usernameError}"
        >
        ....

Why is this not working? 为什么这不起作用?

It appears that this error was being caused because the BindingAdapter was not being compiled, as a result of a source error elsewhere in completely unrelated code. 似乎是由于完全不相关的代码中其他地方的源错误导致未编译BindingAdapter引起此错误。 That other source error (a typo so a variable being referred to was declared using a different name and so did not exist) was not clear in the build error log but once I saw it in the source code it was easy to fix and in turn fixed the BindingAdapter issue. 在构建错误日志中还不清楚其他源错误(使用不同名称声明了错别字,因此引用了变量,因此不存在),但是一旦我在源代码中看到它,就很容易修复,反过来修复了BindingAdapter问题。

If you see this error, check for other possible build errors in the source and build logs. 如果看到此错误,请检查源和构建日志中是否存在其他可能的构建错误。

Firstly, setErrorText is public so you do NOT need define in binding adapter . 首先, setErrorText是公共的,因此您不需要在binding adapter定义。 It still works without define errorText in BindingAdapter class ( Confirmed ! ) 在BindingAdapter类中没有定义errorText情况下仍然可以正常工作(已确认!)

If you want to define in binding adapter, you have to change as below: 如果要在绑定适配器中定义,则必须进行如下更改:

@BindingAdapter("app:errorText")

Hopes this help ! 希望对您有所帮助!

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

相关问题 Android数据绑定:找不到属性app:list的setter - Android data binding : Cannot find setter for attribute app:list 在数据绑定中找不到属性的设置器 - Cannot find the setter for attribute in Data binding 未调用 Android `@BindingAdapter` setter - Android `@BindingAdapter` setter not being called AndroidX迁移-数据绑定错误msg:找不到参数类型为int的属性“ android:visibility”的设置器 - AndroidX migration - data binding error msg:Cannot find the setter for attribute 'android:visibility' with parameter type int 侦听器绑定; 找不到二传手 - Listener Binding; Cannot Find the Setter Java Android 数据绑定:@Bindable 和@BindingAdapter 有什么区别 - Java Android Data Binding : what is the difference between @Bindable and @BindingAdapter 我可以在Android上将视图作为数据绑定BindingAdapter的输入吗? - Can I have a View as input to a data binding BindingAdapter on Android? Android数据绑定:找不到属性android:onClick的setter - Android data binding: can't find setter for attribute android:onClick 如何在数据绑定android中的BindingAdapter中将多个视图作为参数传递? - How to pass multiple views as parameters in BindingAdapter in Data binding android? Android数据绑定错误:找不到我的自定义@BindingAdapter的符号 - Android databinding error: cannot find symbol of my custom @BindingAdapter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM