I have implemented a recycle view On drag & drop the sorting item in the recycle view. But sorting is not accurate, sorting not working properly. I tried write below code
@Overid
private void onDrop(int from, int to) { // this listener only calls when item Droped after drag
ExerciseDetails moveItem = items.remove(from);
items.add(moveItem, to)
int minPosition = from > to ? to : from;
int maxPosition = from > to ? from : to;
// now the item index is the sort index of ExerciseDetails
for (int i = minPosition; i <= maxPosition; i++) {
ExerciseDetails item = items.get(i);
item.setOrder(i);
exercisesDAO.updateOrder(i, item.getExDetailsId());
}
// notify recyclerview to refresh the position of item dragged
adapter.notifyItemMoved(from, to)
}