1

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.

Vinod Pattanshetti
  • 2,465
  • 3
  • 22
  • 36

1 Answers1

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