我是数据绑定的新手,试图绑定recyclerview并收到以下错误。我正在关注github存储库。
android.databinding.tool.util.LoggedErrorException:找到数据绑定 错误。数据绑定错误 msg:找不到用于的setter 参数类型的属性“ app:data” java.util.List上 android.support.v7.widget.RecyclerView。文件:D:\ Android \ All Demo \ TextAndImageSwitcher \ app \ src \ main \ res \ layout \ activity_list_data_binding.xml loc:17:24-17:45 \数据绑定错误
查看模型文件:
public class ListViewModel extends BaseObservable
{
private Context context;
public ListRecyclerAdapter listRecyclerAdapter;
public List<User> userList;
public ListViewModel(final Context context)
{
this.context = context;
userList = new ArrayList<>();
listRecyclerAdapter = new ListRecyclerAdapter(context, userList);
}
public void setUp()
{
populateData();
}
public void tearDown()
{
}
@Bindable
public List<User> getData()
{
return this.userList;
}
@Bindable
public ListRecyclerAdapter getListRecyclerAdapter()
{
return this.listRecyclerAdapter;
}
private void populateData() {
for (int i =0;i<=50;i++){
userList.add(new User("Name("+i+")", "Mobile("+i+")", "Email("+i+")", "Address("+i+")"));
}
notifyPropertyChanged(BR.data);
}
}
我的xml文件:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="listViewModel"
type="com.example.admin.textandimageswitcher.ListViewModel"/>
</data>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ListDataBindingActivity">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:adapter="@{listViewModel.listRecyclerAdapter}"
app:data="@{listViewModel.userList}"
android:id="@+id/list_data_binding_recycler">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</layout>