Android:将不同的内容从viewmodel传递到不同的include标记

Android:将不同的内容从viewmodel传递到不同的include标记,android,android-layout,data-binding,android-include,Android,Android Layout,Data Binding,Android Include,在我的任务应用程序中,我想对任务概述使用数据绑定。我将任务分为三类:过期、今天和未来 My task_overview.xml定义了以下viewmodel(其中包含三个具有不同任务的ArrayList) 我的layout_task_list.xml如下所示 <include layout="@layout/layout_task_list" android:id="@+id/overdued_tasks_list"

在我的任务应用程序中,我想对任务概述使用数据绑定。我将任务分为三类:过期、今天和未来

My task_overview.xml定义了以下viewmodel(其中包含三个具有不同任务的ArrayList)

我的layout_task_list.xml如下所示

<include layout="@layout/layout_task_list"
                     android:id="@+id/overdued_tasks_list"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     app:layout_constraintTop_toBottomOf="@id/headline"/>

            <include layout="@layout/layout_task_list"
                     android:id="@+id/todays_tasks_list"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     app:layout_constraintTop_toBottomOf="@id/overdued_tasks_list"/>

            <include layout="@layout/layout_task_list"
                     android:id="@+id/future_tasks_list"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     app:layout_constraintTop_toBottomOf="@id/todays_tasks_list"/>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">
<data>
    <variable
        name="tasks"
        type="android.databinding.ObservableArrayList" />
</data>

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.AppCompatTextView
        android:id="@+id/subheading"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="@style/SubheadlineWithBackground"
        tools:text="Heute"/>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/task_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/spacing_large"
        android:layout_marginRight="@dimen/spacing_large"
        android:nestedScrollingEnabled="false"
        app:entries="@{tasks}" //recyclerviewbinding is already there
        app:layoutManager="android.support.v7.widget.LinearLayoutManager"
        app:layout_constraintTop_toBottomOf="@id/subheading"/>
</android.support.constraint.ConstraintLayout>

正如您可能建议的那样……代码不起作用。将显示此错误消息

data binding error ****msg:Cannot find the setter for attribute 'app:entries' with parameter type android.databinding.ObservableList<de.taskapp.data.entity.Task> on de.molske.einfachmachen.databinding.LayoutTaskListBinding. file:/Users/app/src/main/res/layout/layout_task_overview.xml loc:38:40 - 38:60 ****\ data binding error ****
数据绑定错误****msg:在de.molske.einfachmachen.databinding.LayoutTaskListBinding上找不到参数类型为android.databinding.observateList的属性“app:entries”的setter。文件:/Users/app/src/main/res/layout/layou_task_overview.xml loc:38:40-38:60****\data binding error****
好的,是的,它告诉我他找不到app:entries的setter…但是有没有一种“漂亮”的方式将三个列表传递给三个include布局?我不喜欢为了能够通过不同的列表而将同一版面复制粘贴三次的想法

提前谢谢


(注:我知道有可能通过java/android代码解决这个问题,但我想知道是否有一种数据绑定方法;-)

好的,经典的我。在谷歌搜索了几次之后,我找到了解决办法。将下一行添加到包含文件的
数据
-部分,一切正常

<import type="java.util.List"/>
<import type="de.molske.einfachmachen.data.entity.Task"/>
<variable name="title" type="java.lang.String"/>
<variable
    name="tasks"
    type="List&lt;Task&gt;"/>

定义
任务
变量的确切类型似乎很重要。因为它的类型是泛型
,而不是定义类型的

data binding error ****msg:Cannot find the setter for attribute 'app:entries' with parameter type android.databinding.ObservableList<de.taskapp.data.entity.Task> on de.molske.einfachmachen.databinding.LayoutTaskListBinding. file:/Users/app/src/main/res/layout/layout_task_overview.xml loc:38:40 - 38:60 ****\ data binding error ****
<import type="java.util.List"/>
<import type="de.molske.einfachmachen.data.entity.Task"/>
<variable name="title" type="java.lang.String"/>
<variable
    name="tasks"
    type="List&lt;Task&gt;"/>