I am working on a RecyclerView there is one thing I want to know, How do I move selected positions or items of the recyclerview list to the top of the list in the recyclerview adapter itself.Any better suggestions are most welcome.
Asked
Active
Viewed 975 times
1
-
What have you done for this? – Ankita Sep 28 '17 at 05:17
-
I am populating the list as per positions. If I select the 10th item it should jump to 0th position. – Vinod Pattanshetti Sep 28 '17 at 05:18
-
1Possible duplicate of [Scroll RecyclerView to show selected item on top](https://stackoverflow.com/questions/26875061/scroll-recyclerview-to-show-selected-item-on-top) – Sandip Sep 28 '17 at 05:22
1 Answers
2
try this first move your select item postion to top of your recyclerview like this
ArrayList<DataModel> arrayList;
DataModel model=arrayList.get(position);
arrayList.remove(position);
arrayList.add(0,model);
than use scrollToPositionWithOffset (int position, int offset) to move to top
scrollToPositionWithOffset Scroll to the specified adapter position with the given offset from resolved layout start
linearLayoutManager.scrollToPositionWithOffset(0, 10);

AskNilesh
- 67,701
- 16
- 123
- 163