在我将其添加到gradle后,我尝试使用 me.tatarka.bindingcollectionadapter:bindingcollectionadapter 库:
compile 'me.tatarka.bindingcollectionadapter:bindingcollectionadapter:1.3.0'
compile 'me.tatarka.bindingcollectionadapter:bindingcollectionadapter-recyclerview:1.3.0'
我在xml文件中使用它,如下所示:
<layout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
>
<data>
<variable name="viewModel" type="com.example.ViewModel"/>
<import type="me.tatarka.bindingcollectionadapter.LayoutManagers" />
</data>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toStartOf="@+id/recycler"
app:layoutManager="@{LayoutManagers.linear()}"
app:items="@{viewModel.items}"
app:itemView="@{viewModel.itemView}"/>
</RelativeLayout>
</layout>
Identifiers must have user defined types from the XML file. LayoutManagers is missing it file
****\ data binding error ****
有人可以帮助我吗? 感谢。
答案 0 :(得分:0)
数据必须是布局的子项
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable name="viewModel" type="com.example.ViewModel"/>
<import type="me.tatarka.bindingcollectionadapter.LayoutManagers" />
</data>
<!-- Rest of your layout -->
</layout>