2016-03-07 168 views
1

当前,我在执行拖放物品在recyclerview中时遇到问题。 我参考做从https://github.com/iPaulPro/Android-ItemTouchHelper-Demo 但是当适配器执行功能:ItemTouchHelper notifyItemMoved到位置不起作用

mListBookMark是Object

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

的ArrayList的。当我拖动项目从位置到位置B,但是当完成拖动回收视图不是数据改变。 我该怎么办? 请给我一些建议!谢谢。

+0

我也有这个问题。现在我解决了在返回true之前放置notifyDataSetChanged()。 – user3528466

回答

1

尝试增加notifyItemChanged()到你的代码,就像这样:

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

这应该根据他们对新位置更新的意见。