【问题标题】:how to put Firebase RecyclerView inside another RecyclerView如何将 Firebase RecyclerView 放入另一个 RecyclerView
【发布时间】:2016-12-23 13:25:26
【问题描述】:

基本上我有一个像家庭作业提醒这样的应用程序

用户可以插入一个主题列表,并在每个主题中插入一个家庭作业列表

我知道这是最糟糕的做法,我不能把 recyclerview 放在另一个里面

但我需要在我的申请中使用,因为不能计算科目+其他内容

我像这样成功地将它插入到firebase数据库中

即subject_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/simple_round"
android:padding="10dp"
android:layout_margin="10dp">
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="2dp"
    android:orientation="horizontal">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Subject: "/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="2"/>
</LinearLayout>
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="2dp"
    android:weightSum="6">
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text="Teacher:"/>
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="2"/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/recyclerview_illness_item_list">
</android.support.v7.widget.RecyclerView>
</LinearLayout>

那就是 homework_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/simple_round"
android:padding="10dp"
android:layout_margin="10dp">
<LinearLayout
    android:layout_width="match_parent"
    android:padding="2dp"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="title:"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="2dp"
    android:orientation="horizontal">
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="description:"/>
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="2dp"
    android:orientation="horizontal">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="deadline:"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</LinearLayout>

而且只有一个 recyclerview 我这样做

adapter = new FirebaseRecyclerAdapter<Test, TestViewHolder>(Test.class, R.layout.test_main_body_item, TestViewHolder.class, reference.child("subjects/98794656")) {
        @Override
        protected void populateViewHolder(TestViewHolder viewHolder, Test model, int position) {
            viewHolder.title.setText(model.getTitle());
            viewHolder.description.setText(model.getDescription());
        }
    };

那么我该如何为一个recycler view Insider 做另一个recyclerview 呢??

谢谢

【问题讨论】:

  • 您找到解决方案了吗?我正在努力解决同样的问题

标签: java android firebase firebase-realtime-database firebaseui


【解决方案1】:

您想要做的是检测点击了什么并导航到另一个活动以显示也包含正确的数据列表?

但在此之前,您需要一个 EXTRA_KEY 捆绑包来告诉您的新活动它需要从他的父母那里接收一些东西。例如:“嘿,我正在向您发送一个包裹,将其解压缩并在您的环境中明智地使用它。”

现在创建 EXTRA BUNDLE 很简单。只需将其写入本地变量即可。

您要导航到的活动,把它放在那里:

public static final String EXTRA_NAME = "cheese_name";
public static final String EXTRA_POST_KEY = ""; `

Intent intent = getIntent();
final String cheeseName = intent.getStringExtra(EXTRA_NAME);`

获取帖子的数据库引用键:

            viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    // Launch PostDetailActivity
                    Intent intent = new Intent(getActivity(),   CheeseDetailActivity.class);

  //How you are sending something to another activity


intent.putExtra(CheeseDetailActivity.EXTRA_POST_KEY, postKey);
                    startActivity(intent);
                }
            });


    }
};

您引用了一个孩子("test")

adapter = new FirebaseRecyclerAdapter<Test, TestViewHolder>(Test.class, R.layout.test_main_body_item, TestViewHolder.class, reference.child("test")) {
    @Override
    protected void populateViewHolder(TestViewHolder viewHolder, Test model, int position) {

    final DatabaseReference postRef = getRef(position);


            // Set click listener for the whole post view
            final String postKey = postRef.getKey();

        viewHolder.title.setText(model.getTitle());
        viewHolder.description.setText(model.getDescription());
    }
};

【讨论】:

  • 不是这样的,是的,我指的是一个不存在的节点-错误-。问题是我有 2 个列表,1 个用于主题,另一个用于每个主题的家庭作业,我可以创建主题列表,当任何人被点击时,它的家庭作业将被列出,我目前正在使用下面的添加视图来解决它点击了一个。
  • 好的。我会在桌面上回来
猜你喜欢
  • 1970-01-01
  • 2017-03-18
  • 1970-01-01
  • 1970-01-01
  • 2016-01-24
  • 1970-01-01
  • 1970-01-01
  • 2021-09-30
  • 1970-01-01
相关资源
最近更新 更多