I am using “drag & drop” and “swipe-to-dismiss” in RecyclerView with ItemTouchHelper. Without any library, according to this tutorial . It works perfectly. But the problem occurs when there is scroll in RecyclerView . When I start to drag first item down, first and second elements swap positions, RecyclerView is scrolled up and the first element(that I am dragging) occurs on bottom before last element(many swipes occure because of RecyclerView scrolling). It happens very fast, so I cannot put first element wherever I want.
Note that It happens only with first element, also only when dragging down.
I think this happens because when second element goes to position 1, third element goes to second position and also swipes with first element, and the same with other elements, they are all swiped with first element. How can I fix this.
This is what is called when first item changes position with second (and also with any dragging when items swap positions). After one swap, one item goes done:
@Override
public void onItemMove(int fromPosition, int toPosition) {
if (fromPosition < toPosition) {
for (int i = fromPosition; i < toPosition; i++) {
Collections.swap(categories, i, i + 1);
}
} else {
for (int i = fromPosition; i > toPosition; i--) {
Collections.swap(categories, i, i - 1);
}
}
notifyItemMoved(fromPosition, toPosition);
}