此绑定属性无法构建,错误如下:
找不到属性“errorText”的setter
@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没有被编译造成的,因为完全不相关的代码中的其他地方存在源错误。那个其他的源错误(一个错误所以被引用的变量是使用不同的名称声明,所以不存在)在构建错误日志中不明确但是一旦我在源代码中看到它就很容易修复,反过来修复了BindingAdapter问题。
如果看到此错误,请检查源和构建日志中是否存在其他可能的构建错误。
首先,setErrorText
是公开的,所以你不需要在binding adapter
中定义。它仍然可以在BindingAdapter类中定义errorText
(确认!)
如果要在绑定适配器中定义,则必须更改如下:
@BindingAdapter("app:errorText")
希望对你有所帮助!