You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
=== DragGridActivity ===
if (fromPosition < toPosition) {
for (int i = fromPosition; i < toPosition; i++)
Collections.swap(mDataList, i, i + 1);
} else {
for (int i = fromPosition; i > toPosition; i--)
Collections.swap(mDataList, i, i - 1);
}
不知道为何,这个bug一直没人提,原因出在这里:
Collections.swap(data, fromPosition, toPosition); // 这里是交换 fromPosition 的数据跟 toPosition数据进行交换
adapter.notifyItemMoved(fromPosition, toPosition); // 这里是将fromPosition 的移动到 toPosition
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
当fromPosition跟toPosition是临近的则没有问题,如9移动到8,正常;但当9直接移动到7就错了,展示的数据是[0, 1, 2, 3, 4, 5, 6, 9, 7, 8],而如果直接使用Collections.swap,则实际数据是 [0, 1, 2, 3, 4, 5, 6, 9, 8, 7],就会导致不一致,所有这里使用Collections.swap有问题
The text was updated successfully, but these errors were encountered: