I got this error when I try to biding RecyclerView
Error:(15, 22) Cannot find the setter for attribute 'app:items' with parameter type
android.databinding.ObservableArrayList<com.toong.databindingdemo.recycler.UserViewModel
onandroid.support.v7.widget.RecyclerView
.
Here is my code:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="usersViewModel"
type="com.toong.databindingdemo.recycler.UsersViewModel" />
</data>
<android.support.v7.widget.RecyclerView
android:id="@+id/activity_users_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:items="@{usersViewModel.users}"
/>
</layout>
But in UsersViewModel
I already have a public users array
package com.toong.databindingdemo.recycler;
import android.databinding.BaseObservable;
import android.databinding.Bindable;
import android.databinding.ObservableArrayList;
public class UsersViewModel extends BaseObservable{
@Bindable
public ObservableArrayList<UserViewModel> users;
public UsersViewModel()
{
this.users = new ObservableArrayList<>();
}
}
I have clean and rebuild project but it still not working. How can I fix this error?
There is no property like app:items
in RecyclerView
. You need to create custom Binding method for that
@BindingAdapter("items")
public static void entries(RecyclerView recyclerView, String[] array) {
//write your code to set RecyclerView adapter.
}
change type of array
to your required datatype.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With