Vinod Pattanshetti
Vinod Pattanshetti

Reputation: 2583

How do I move selected items of recyclerview list to the top of recyclerview list

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.

Upvotes: 1

Views: 1045

Answers (1)

AskNilesh
AskNilesh

Reputation: 69709

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);

Upvotes: 2

Related Questions