如何在单击cardview中的按钮时填充Recyclerview

时间:2015-08-21 10:28:19

标签: android android-recyclerview android-cardview

我陷入了一种我无法继续前进的局面。实际上我有一个cardViews的RecyclerView,并且有一个适配器用数据填充卡。我必须在卡片中显示一些餐馆。点击Cardview中的按钮,我必须显示另一个回收站视图,其中将包含包含该餐厅分支的cardViews。

这里我只有一个可以返回两种类型数据的模型。我不知道是否应该使用1个带多个viewHolders或2个适配器的适配器。我的视图也是一个单一的布局。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="@dimen/margin_medium">

    <android.support.v7.widget.CardView
        android:id="@+id/recipient_card"
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:elevation="20dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="@dimen/receipient_card_height"
                android:orientation="horizontal"
                android:id="@+id/linear_layout">


                <ImageView
                    android:id ="@+id/arrow_button"
                    android:layout_width="@dimen/size_info_icon"
                    android:layout_height="@dimen/size_info_icon"
                    android:layout_marginLeft="@dimen/activity_horizontal_margin"
                    android:layout_gravity="center" />

                <com.inquirly.opinify.View.CustomTextView
                    android:id="@+id/business_name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    style="@style/label_small"
                    android:layout_marginLeft="@dimen/activity_horizontal_margin"
                    android:layout_gravity="center"
                    android:layout_weight="10"
                    android:text="JustBake"/>

                <ImageView
                    android:id="@+id/recipient_business_logo"
                    android:layout_marginLeft="@dimen/margin_small"
                    android:layout_gravity="center"
                    android:layout_width="@dimen/receipient_business_logo_size"
                    android:layout_height="@dimen/receipient_business_logo_size"/>


                <ImageView
                    android:id="@+id/expand_button"
                    android:layout_marginLeft="@dimen/margin_small"
                    android:layout_gravity="center"
                    android:padding="@dimen/margin_medium"
                    android:layout_width="@dimen/height_button"
                    android:layout_height="@dimen/height_button"
                    />

            </LinearLayout>

        </RelativeLayout>
    </android.support.v7.widget.CardView>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_recipient_branch_list"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:visible= "false"
        android:padding="@dimen/margin_medium"/>


</RelativeLayout>

我在开始时使内部recyclelerView不可见。当用户点击主回收商的CardView按钮中的箭头按钮时,第二个recylerview应该出现在分支列表中。

这是我想要实现的屏幕截图。 enter image description here

1 个答案:

答案 0 :(得分:2)

为什么不将工具改为可扩展RecyclerView。查看this文章。此外,建议您检查this提问。