【问题标题】:Android Data Binding BindingAdapter: "Cannot find the setter"Android 数据绑定 BindingAdapter:“找不到设置器”
【发布时间】:2017-11-22 13:19:14
【问题描述】:

此绑定属性构建失败,出现错误:

找不到属性“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}"
        >
        ....

为什么这不起作用?

【问题讨论】:

  • 哦,没有数据绑定的恐怖
  • 也许需要改变这个? @BindingAdapter({"usernameError"})
  • 你能上传整个xml文件吗?

标签: android android-databinding


【解决方案1】:

看起来这个错误是因为没有编译 BindingAdapter 引起的,这是由于其他地方的源错误完全不相关的代码。构建错误日志中并不清楚其他源错误(一个错字,因此引用的变量使用不同的名称声明,因此不存在)在构建错误日志中不清楚,但一旦我在源代码中看到它就很容易修复,反过来修复了 BindingAdapter 问题。

如果您看到此错误,请在源代码和构建日志中检查其他可能的构建错误。

【讨论】:

    【解决方案2】:

    首先,setErrorText 是公开的,因此您不需要在 binding adapter 中定义。 它仍然可以在没有定义 errorText 的 BindingAdapter 类中工作(已确认!)

    如果你想在绑定适配器中定义,你必须改变如下:

    @BindingAdapter("app:errorText")

    希望有帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-05
      • 1970-01-01
      • 2017-06-29
      • 2017-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多