使用DataBinding-MVVM的RecyclerView

时间:2017-06-23 09:34:07

标签: android android-databinding android-mvvm

我正在使用Databinding-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的值。

0 个答案:

没有答案