0

I have a RecyclerView that is within a Fragment that extends FragmentStatePagerAdapter. I want to scroll the recyclerView when i click a button of some sort. The problem is that using mRecyclerView.smoothScrollToPosition(selectedPosition) is scrolling the next fragment. Is there a way to capture the current fragment and perform the scroll operation on the it? All the answers I found involve fragments that extend FragmentPagerAdapter. I can't use this fragment because, my app has more than a 1000 fragments, which should be loaded on the case by case bases.

Girum A
  • 63
  • 10

1 Answers1

0

After many hours of serching i was able to find a great answer on StackOverflow. With in my app clicking a button scrolls the recyclerview to the desired position.

int pagePosition = mViewPager.getCurrentItem();
MyAdaptor adaptor = (MyAdaptor) mViewPager.getAdapter();
RecyclerView recyclerView = ((MyFragment) adaptor.instantiateItem(mViewPager, pagePosition)).mRecyclerView;
recyclerView.getLayoutManager().smoothScrollToPosition(recyclerView, null, mScrollToPosition);
Girum A
  • 63
  • 10