Good day.
How can RecyclerView be implemented inside RecyclerView?
I thought to do with the help of an Array, they say, a separate RV is created for each new Item; or with the help of "General", which simply changes the list and data depending on the selected item.

(pictures for clarity)
External RV
TopLvl RV
Interior
DeepLvl RV

  • one
    Why do you need this? O.O. - Rostislav Dugin
  • It is necessary for the project, and just for the overall development :) - Slyly

2 answers 2

You can use the tips above, but from myself I can add the following: you shouldn’t do that with RecyclerView .


It is very likely that there will be problems in operation (at least with performance with a large number of RecyclerView ) and with 100% probability there will be a problem with dirty and heavily supported code.


The most optimal solution, as for me, is to create markup with a TextView , which will look like elements of a ListView . RecyclerView will find them once (via the findViewById method) and there will be no further problems - boldly insert information.

    In the case of ListView, there was a problem with scrolling - what exactly is scrolling right now, the whole page or just an element of the list?

    Solution: To create multiple ListViews on the same page, create any number of WidgetStaticListView widgets in the markup file. And then just initialize each one of them in the code, adding an adapter to them.

    For example:

    Create a class WidgetStaticListView and place the code in it (on this page below). In the markup file we create, for example, THREE WidgetStaticListView element inside the ScroolView element ScroolView

     <?xml version="1.0" encoding="utf-8"?> <ScrollView android:layout_height="match_parent" android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <ваш_пакет.WidgetStaticListView android:id="@+id/wsListView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> </ваш_пакет.WidgetStaticListView> <ваш_пакет.WidgetStaticListView android:id="@+id/wsListView2" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> </ваш_пакет.WidgetStaticListView> <ваш_пакет.WidgetStaticListView android:id="@+id/wsListView3" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> </ваш_пакет.WidgetStaticListView> </ScrollView> 

    In activism, we write for lists:

     WidgetStaticListView wslv1 = (WidgetStaticListView) findViewById(R.id.wsListView1); WidgetStaticListView wslv2 = (WidgetStaticListView) findViewById(R.id.wsListView2); WidgetStaticListView wslv3 = (WidgetStaticListView) findViewById(R.id.wsListView3); //отдельно создаем адаптеры и присваиваем их к этим спискам wslv1.setAdapter(adapter1); wslv2.setAdapter(adapter2); wslv3.setAdapter(adapter3); 

    WidgetStaticListView class WidgetStaticListView :

     //some listview on one view //add in xml-layout // //<...your_path.. .WidgetStaticListView // android:id="@+id/wsListView" // android:layout_width="match_parent" // android:layout_height="wrap_content" // android:orientation="vertical"> // </...your_path.. .WidgetStaticListView> import android.content.Context; import android.database.DataSetObserver; import android.util.AttributeSet; import android.view.View; import android.widget.Adapter; import android.widget.LinearLayout; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class WidgetStaticListView extends LinearLayout { protected Adapter adapter; protected Observer observer = new Observer(this); public WidgetStaticListView(Context context) { super(context); } public WidgetStaticListView(Context context, AttributeSet attrs) { super(context, attrs); } public void setAdapter(Adapter adapter) { if (this.adapter != null) this.adapter.unregisterDataSetObserver(observer); this.adapter = adapter; adapter.registerDataSetObserver(observer); observer.onChanged(); } private class Observer extends DataSetObserver { WidgetStaticListView context; public Observer(WidgetStaticListView context) { this.context = context; } @Override public void onChanged() { List<View> oldViews = new ArrayList<View>(context.getChildCount()); for (int i = 0; i < context.getChildCount(); i++) oldViews.add(context.getChildAt(i)); Iterator<View> iter = oldViews.iterator(); context.removeAllViews(); for (int i = 0; i < context.adapter.getCount(); i++) { View convertView = iter.hasNext() ? iter.next() : null; context.addView(context.adapter.getView(i, convertView, context)); } super.onChanged(); } @Override public void onInvalidated() { context.removeAllViews(); super.onInvalidated(); } } } 

    Note: you will most likely be able to repeat this trick for RecyclerView . Good luck!