8

I have a RecyclerView that has a PagedListAdapter.

When I put the RecyclerView inside NestedScrollView the PagedList cannot compute the end of the list so start requests continuous burst for new data.

The main question is How should I use PagedListAdapter inside NestedScrollView?

Letsintegreat
  • 2,764
  • 4
  • 16
  • 35
SamiAzar
  • 1,041
  • 8
  • 25

2 Answers2

0

I had a similar problem, and it seems to be caused by the fact that NestedScrollView provides infinite dimensions and so RecyclerView will layout all its children. so I looked on github and found an implementation of NestedScrollView that solved the problem by passing View.MeasureSpec.AT_MOST down to the RecyclerView:

https://gist.github.com/danaimset/abacaa50d746a4537686a08ecc33c1a9

colidyre
  • 3,035
  • 11
  • 30
  • 43
gianpaolo
  • 205
  • 2
  • 16
0

Based on Android documentation:

Never add a RecyclerView or ListView to a scroll view. Doing so results in poor user interface performance and a poor user experience.

The best new way is to use MergeAdapter. It added to Recyclerview v1.2.0alpha. So add this dependency:

implementation "androidx.recyclerview:recyclerview:1.2.0-alpha03"

If you want to put two Adapters in one recyclerView, follow this Guide:

then make an instance of MakeAdapter and pass your adapters on it then set it as RecyclerViewAdapter:

MergeAdapter ma = new (firstAdapter, secondAdapter);
myRecyclerView.setAdapter(ma);

If you have a layout and Pagedlist, follow this Guide:

Then Make and Simple ViewHolder and put the first layout on it. Then make MergeAdapter then add your layout's adapter and then PagedList's adapter, then add adapter of PagedList:

MergeAdapter ma = new MergeAdapter();
ma.addAdaper(simpleAdapter);
ma.addAdapter(pagedListAdapter);

then set this mergeAdapter to recyclerView's adapter;

myRecyclerView.setAdapter(ma);
DrMorteza
  • 1,807
  • 1
  • 14
  • 26