Android 数据绑定:找不到属性 app:list 的 setter
Android data binding : Cannot find setter for attribute app:list
这是我的列表视图
<ListView
android:id="@+id/productListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:list="@{page.results}"/>
我收到这个错误:
java.lang.RuntimeException: Found data binding errors.
****/ data binding error ****msg:Cannot find the setter for attribute 'app:list' with parameter type java.util.List on android.widget.ListView.
loc:33:20 - 33:31
****\ data binding error ****
这是我的 BindingAdapter
@BindingAdapter({"bind:list"})
public static void bindList(Context context, ListView view, ObservableArrayList<Result> list) {
ProductsAdapter arrayAdapter = new ProductsAdapter(context,list);
view.setAdapter(arrayAdapter);
}
有人可以帮忙解决这个问题吗?
您应该离开 bind 命名空间。只有 @BindingAdapter("list")
就足够了。
另外你不需要 Context
参数应该使用 List<Result>
而不是 ObservableArrayList<Result>
@BindingAdapter("list")
public static void bindList(ListView view, List<Result> list) {
Context context = view.getContext();
view.setAdapter(new ProductsAdapter(context, list));
}
这是我的列表视图
<ListView
android:id="@+id/productListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:list="@{page.results}"/>
我收到这个错误:
java.lang.RuntimeException: Found data binding errors. ****/ data binding error ****msg:Cannot find the setter for attribute 'app:list' with parameter type java.util.List on android.widget.ListView. loc:33:20 - 33:31 ****\ data binding error ****
这是我的 BindingAdapter
@BindingAdapter({"bind:list"})
public static void bindList(Context context, ListView view, ObservableArrayList<Result> list) {
ProductsAdapter arrayAdapter = new ProductsAdapter(context,list);
view.setAdapter(arrayAdapter);
}
有人可以帮忙解决这个问题吗?
您应该离开 bind 命名空间。只有 @BindingAdapter("list")
就足够了。
另外你不需要 Context
参数应该使用 List<Result>
而不是 ObservableArrayList<Result>
@BindingAdapter("list")
public static void bindList(ListView view, List<Result> list) {
Context context = view.getContext();
view.setAdapter(new ProductsAdapter(context, list));
}