Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ItemTouchHelper notifyItemMoved from to position not working

Current,I am having a problem when execute drag and drop item in recyclerview. I am doing with reference from https://github.com/iPaulPro/Android-ItemTouchHelper-Demo But when execute function in adapter:

mListBookMark is ArrayList of Object

@Override
public boolean onItemMove(int fromPosition, int toPosition) {
    Collections.swap(mListBookMark, fromPosition, toPosition);
    notifyItemMoved(fromPosition, toPosition);
    return true;
}

When I drag item from position a to position b but when finish drag recycler view not data changed. How must I do? Please give some suggestion for me! Thank you.

like image 883
Nihongo JBenkiyo Avatar asked Mar 07 '16 11:03

Nihongo JBenkiyo


1 Answers

Try adding notifyItemChanged() to your code, like this:

@Override
public boolean onItemMove(int fromPosition, int toPosition) {
    Collections.swap(mListBookMark, fromPosition, toPosition);
    notifyItemMoved(fromPosition, toPosition);
    notifyItemChanged(fromPosition);
    notifyItemChanged(toPosition);
    return true;
}

This should update the views based on their new position.

like image 65
hgzech Avatar answered Sep 18 '22 13:09

hgzech