RecyclerView放入另一个RecyclerView

RecyclerView放入另一个RecyclerView

本文介绍了如何将Firebase RecyclerView放入另一个RecyclerView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我有一个应用程序,像一个家庭作业提醒用户可以插入一个主题列表,并在每个主题的作业列表$ /

我知道这是最糟糕的做法,我不能把recyclerview放在另一个里面,但是我在申请中需要这样做,因为主题不能计算在内+其他的东西



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



即subject_item.xml

 < ?xml version =1.0encoding =utf-8?> 
< LinearLayout xmlns:android =http://schemas.android.com/apk/res/android
android:orientation =verticalandroid: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 =horizo​​ntal >
< 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 =horizo​​ntal
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.0encoding =utf-8?> 
< LinearLayout xmlns:android =http://schemas.android.com/apk/res/android
android:orientation =verticalandroid: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$ b $ android:orientation =horizo​​ntal >
< 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 =horizo​​ntal GT&;
< 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 =horizo​​ntal >
< 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 i像这样做

  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());
}
};

那么我该如何做一个回收者视图insider另一个recyclerview ??



感谢

解决方案

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



但在此之前,您需要一个 EXTRA_KEY 它需要从父母那里得到一些东西。例如:嘿,我给你发一个包,解压并在你的环境中明智地使用它。

现在创建EXTRA BUNDLE很简单。只要在你的本地变量
中写入这个你想要导航到的行为,把它放在那里

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

$ b

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

获取数据库引用键为职位也。

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

//如何将某个东西发送给另一个活动

$ b 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。 (TestView)()){
@Override
protected void populateViewHolder(TestViewHolder viewHolder,Test model,int position){

final DatabaseReference postRef = getRef(position);


//设置整个发布视图的点击监听器
final String postKey = postRef.getKey();

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


basically i am having an application like a homework reminder

the user can insert a list of subjects and in each subject a list of homeworks

i know its the worst practice and i cant put recyclerview inside another one

but i need that in my application as subjects cannot be counted+other things

i inserted it in firebase database successfuly like that

that is 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>

and that is 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>

and for only one recyclerview i do it like that

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());
        }
    };

so how can i do for a recycler view insider another recyclerview ??

thanks

解决方案

What you want to do is detect what is clicked and navigate to another activity to show the list of data that also contains right?

But before that you need an EXTRA_KEY bundle to tell your new activity that it needs to receive something from his parent. e.g: " Hey, i am sending you a package, extract it and use it wisely in your environment."

Now to create that EXTRA BUNDLE is simple. Just write this in your local variableThe activity you want navigate to, put this there 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);`

Get the database reference key for the post also.

            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);
                }
            });


    }
};

You referenced to a child ("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());
    }
};

这篇关于如何将Firebase RecyclerView放入另一个RecyclerView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 03:21