OSDN Git Service

ListView.setItemChecked(p, false) always clears all items.
authorBrett Chabot <brettchabot@google.com>
Mon, 3 Aug 2009 23:40:02 +0000 (16:40 -0700)
committerBrett Chabot <brettchabot@google.com>
Tue, 4 Aug 2009 00:40:38 +0000 (17:40 -0700)
This fixes the bug where, in SINGLE_CHOICE_MODE, calling
ListView.setItemChecked(x, false) would always uncheck all
items, even if another item, y, was currently checked.

core/java/android/widget/ListView.java

index 515b581..02a137d 100644 (file)
@@ -3264,12 +3264,13 @@ public class ListView extends AbsListView {
         if (mChoiceMode == CHOICE_MODE_MULTIPLE) {
             mCheckStates.put(position, value);
         } else {
-            // Clear the old value: if something was selected and value == false
-            // then it is unselected
-            mCheckStates.clear();
-            // If value == true, select the appropriate position
+            // Clear all values if we're checking something, or unchecking the currently
+            // selected item
+            if (value || isItemChecked(position)) {
+                mCheckStates.clear();
+            }
             // this may end up selecting the value we just cleared but this way
-            // we don't have to first to a get(position)
+            // we ensure length of mCheckStates is 1, a fact getCheckedItemPosition relies on
             if (value) {
                 mCheckStates.put(position, true);
             }