Nih*_*iyo 4 drag-and-drop drag recycler-adapter android-recyclerview
目前,我在recyclerview中执行拖放项时遇到问题.我正在参考https://github.com/iPaulPro/Android-ItemTouchHelper-Demo 但是当在适配器中执行函数时:
mListBookMark是Object的ArrayList
@Override
public boolean onItemMove(int fromPosition, int toPosition) {
Collections.swap(mListBookMark, fromPosition, toPosition);
notifyItemMoved(fromPosition, toPosition);
return true;
}
Run Code Online (Sandbox Code Playgroud)
当我将项目从位置a拖动到位置b但是当完成拖动回收器视图时没有更改数据.我该怎么办?请给我一些建议!谢谢.
尝试添加notifyItemChanged()到您的代码,如下所示:
@Override
public boolean onItemMove(int fromPosition, int toPosition) {
Collections.swap(mListBookMark, fromPosition, toPosition);
notifyItemMoved(fromPosition, toPosition);
notifyItemChanged(fromPosition);
notifyItemChanged(toPosition);
return true;
}
Run Code Online (Sandbox Code Playgroud)
这应该根据新的位置更新视图.
| 归档时间: |
|
| 查看次数: |
1162 次 |
| 最近记录: |