1

I'm using a RecyclerView in conjunction with PagedListAdapter to fetch images from a rest API. The RecyclerView fetches more images as needed when I scroll through it. I would like to simulate scrolling very fast through the RecyclerView but still have onBindViewHolder() get called for each item since the logic inside there is important. Ideally I would like to be at position 50 in the RecyclerView and be able to do something like mRecyclerView.scrollToPosition(300); but that doesn't work since position 300 doesn't exist yet.

Is there a way to programmatically scroll the recyclerView so that it effectively does the same thing as me manually scrolling through it?

Isaac Perez
  • 570
  • 2
  • 15
  • 31
  • Do you want to smooth scroll to position 300? Or instantaneously scroll to it? – user1506104 Oct 19 '18 at 21:41
  • Seems that you need to adjust the settings in `PagedList.Config` (https://developer.android.com/reference/android/arch/paging/PagedList.Config.html#enablePlaceholders) so that either you allow for the list to be all the items, or increase the `prefetchDistance` so that when you are at position 50 the item in position 300 is prefetched. – frozenkoi Oct 19 '18 at 23:28

1 Answers1

0

you can use scrollTo() as following

mRecyclerView.post(new Runnable() {
        @Override
        public void run() {
            mRecyclerView.scrollToPosition(POSITION_TO_SCROLL_TO);
        }
    });
Basil
  • 845
  • 9
  • 24