Android 带有数据绑定MVVM的RecyclerView

Android 带有数据绑定MVVM的RecyclerView,android,android-databinding,android-mvvm,Android,Android Databinding,Android Mvvm,我使用数据绑定mvvm的概念来实现这些事情。我已将recyclerview声明为我的主要活动。像 <layout xmlns:app="http://schemas.android.com/apk/res-auto"> <data> <import type="android.view.View"/> <variable name="ffvm" type="com.example.the

我使用数据绑定mvvm的概念来实现这些事情。我已将recyclerview声明为我的主要活动。像

<layout xmlns:app="http://schemas.android.com/apk/res-auto">
    <data>
        <import type="android.view.View"/>
        <variable
            name="ffvm"
  type="com.example.the_king.apartmentmanagementsystem.ViewModal.
  FragmentViewModal.ViewModal"/>
    </data>
<FrameLayout 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="com.example.the_king.apartmentmanagementsystem.
  Fragment.Fragment_FlatHolder">

 <android.support.v7.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
    </FrameLayout>
</layout>

我的cardview看起来像

<layout>
<data>
    <import type="android.view.View"/>
    <variable
        name="cfhvm"
        type="com.example.the_king.apartmentmanagementsystem.ViewModal.
        CardViewModel.CardViewModal"/>
</data>
  <android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context="com.example.the_king.apartmentmanagementsystem.
    CardView.CardViewFlatHolder"
        layout_width="match_parent"
        android:background="@color/colorPrimaryLight"
        android:elevation="25dp"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
        android:innerRadius="15dp"
        android:thicknessRatio="1.9"
        layout_height="match_parent">
<TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@{cfhvm.firstname+` `+cfhvm.lastname}"
                android:layout_marginLeft="5dp"
                android:textSize="@dimen/text_title"
                />
</android.support.v7.widget.CardView>
</layout>


对于cardview,我已将viewmodel创建为cardviewmodal;对于Recyclerview,我已创建viewmodel,我还创建了用于填充数据的适配器。现在,我弄不清楚如何从包含cardviewmodel的viewmodel设置Recyclerview的值

这个例子可能会对你有所帮助:是的,你的解决方案对我有帮助。@uli请随意投票给我,给我信用现在我不能,因为我只有11个信用。。。当我有能力的时候,我一定会投票支持你的答案@(您刚刚获得了向上投票的特权;)