Nihongo JBenkiyo
Nihongo JBenkiyo

Reputation: 61

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.

Upvotes: 6

Views: 1789

Answers (1)

hgzech
hgzech

Reputation: 99

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.

Upvotes: 8

Related Questions