I have recyclerview
in that I want to change item's position dynamically to top after selecting the item of recyclerview
.
Please suggest best way to achieve the above problem?
You need to swap selected item with top item in list, then notify your adapter about position change. A sample code would look like:
Collections.swap(orderItems.getItems(), position, 0);
notifyItemMoved(position, 0);
Hope it helps!
Try this
String Item = List.get(position);
List.remove(position); // remove item from the list
List.add(0,removedItem); // add at 0 index of your list
notifyDataSetChanged();
linearLayoutManager.scrollToPositionWithOffset(0, 20); // scroll recyclerview to top
OR
recyclerview.getLayoutManager().scrollToPosition(0) // scroll recyclerview to top
OR
recyclerview.smoothScrollToPosition(0); // scroll recyclerview to top
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With