android - 如何通过单击卡片 View 中的按钮来填充回收器 View

标签 android android-recyclerview android-cardview

我陷入了一种无法继续下去的境地。实际上我有一个cardViews 的RecyclerView,并且有一个适配器可以用数据填充卡片。我必须在卡片上显示一些餐馆。单击 Cardview 中的按钮时,我必须显示另一个 recyclerview,该 View 将填充包含该餐厅分支机构的 cardView。

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

<?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>

我一开始就让内部的recyclerView不可见。当用户单击主回收器的 CardView 按钮中的箭头按钮时,第二个回收器 View 应与分支列表一起出现。

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

最佳答案

为什么不实现一个可扩展的 RecyclerView 呢?查看this文章。另外建议您检查this问题出来了。

关于android - 如何通过单击卡片 View 中的按钮来填充回收器 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32138068/

相关文章:

android - Android中大数据加载中的分页 ListView

java - 卡片 View 不可见

android - 改变卡片的背景 (Android cardView)

android - 在 Android 上使用 AWS Cognito 身份池进行 Google 身份验证失败

java - Android View 关闭某些 View 的隐式状态保留

android - ItemTouchHelper - 在第一条跳线后强制放下

java - 如何将 int 转换为在 textView 内设置

java - OnClick 用 fragment 替换 RecyclerView 中的 View

android - CardView 示例不工作

java - 安卓-Arduino蓝牙通讯: app stops reading inputstream