From 64b5a2532c9275d313da7ad1f4651c3311adf99f Mon Sep 17 00:00:00 2001 From: jrfeng Date: Fri, 27 Nov 2020 19:23:57 +0800 Subject: [PATCH] fix bug: 'SelectableHelper#clearSelected()' --- .../main/java/recyclerview/helper/SelectableHelper.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/helper/src/main/java/recyclerview/helper/SelectableHelper.java b/helper/src/main/java/recyclerview/helper/SelectableHelper.java index 53f89c8..65365a5 100644 --- a/helper/src/main/java/recyclerview/helper/SelectableHelper.java +++ b/helper/src/main/java/recyclerview/helper/SelectableHelper.java @@ -142,12 +142,9 @@ public void setSelectMode(SelectMode mode) { /** * 清除所所列表项的选中状态。 */ - @SuppressWarnings("WhileLoopReplaceableByForEach") public void clearSelected() { - Iterator iterator = mSelectedPositions.iterator(); - while (iterator.hasNext()) { - // 不能使用 for 循环,因为该方法会会删除列表中的元素 - deselect(iterator.next()); + for (int position : new ArrayList<>(mSelectedPositions)) { + deselect(position); } notifySelectCountChanged(); }