5

I want to implement an ConcatAdapter like this image:

enter image description here

This page's recyclerView contains these elements:

  • Title
  • Horizontal recyclerView (with pagination)
  • Title
  • Vertical recyclerView (no pagination)
  • Title
  • Horizontal recyclerView (with pagination)

But the problem is I can set only one LayoutManager to recyclerView that holds ConcatAdapter as I know.

How can set different layoutmanager to each adapter? Or any other solution to implement this page with CocantAdapter?

(Why ConcatAdapter? Because it sovle performance prblems of nestedRecyclerView even with recyclerViewPool as I know)

DrMorteza
  • 2,067
  • 2
  • 21
  • 29
  • 1
    Concat adapter is really primitive, it just remaps item positions to contained adapters. You cannot use it for this case. – Pawel Apr 04 '21 at 15:34

2 Answers2

2

This unfortunately is not possible. A RecyclerView adapter is just a component to provide and bind views for each row. A ConcatAdapter is no different, it just redirects from the individual adapters.

If it did have any control over the layout managers it would really defeat the entire point of the modularity of RecyclerView, which is what makes it so powerful in the first place.

You can take a look at the source code here to find out more about how it is implemented.

Henry Twist
  • 5,666
  • 3
  • 19
  • 44
  • Thanks, @henry. So what's the solution? How can I implement it to be smooth and performant? – DrMorteza Apr 05 '21 at 03:27
  • 2
    Well I've never had a performance issue with having the horizontal `RecyclerView` nested. There's not a solution that I know of that will allow both your horizontal layouts to share a view pool I'm afraid! – Henry Twist Apr 05 '21 at 11:12
1

Simple solution is to create a Viewpool in the Activity/Fragment. The Adapter for the recyclerview has 2 different types of items, The regular one and the other that actually has a recyclerview with the horizontal layout as Adapter in it.

So a Viewholder that holds a recyclerview inside with its own viewholders.

Then you just grab the created viewpool from the activity to assign it as the shared Pool to all of the adapters with the horizontal scroll, thats it :-)

Concat Adapter doesnt help with this im afraid so this would be my alternative solution

Finn Marquardt
  • 512
  • 3
  • 9