androidkotlinandroid-recyclerviewheterogeneous

How to create multi-layered RecyclerView adapter?


In my Android project I have a complex RecyclerView. The structure of my RecyclerView looks like the attached image.

In a few words, I have a main RecyclerView which contains a CardView, within the CardView I have another RecyclerView and each element can expand and collapse.

I have tried using a nested RecyclerView implementation (which is easy to find in Google by typing "Nested RecyclerView"), but this implementation has a bottleneck. When I call onBindViewHolder it calls setAdapter method and causes a bug when I scroll the RecyclerView.

Could you please give me any tips on how to implement such RecyclerView? What is the best way of building such Recycler adapters?

Here is an image how it looks like

Here is what I found about my way of implementing RecyclerView


Solution

  • This can be easily done with Concat Adapter.

    https://www.youtube.com/watch?v=n_mrrva_z

    this is my Mockup app using Concat adapter.

    Think of Concat Adpater as an arrayList. Its coded like ConcatAdapter(HeaderAdapter, Adapter2, HorizontalAdapter)