Calling setItemChecked(p, true) twice would toggle the selection in ListView.
This fixes a bug in ListView#setItemChecked(int, boolean). Calling the method
twice would cause the checked state to be toggled instead of remaining the
same.
diff --git a/core/java/android/widget/ListView.java b/core/java/android/widget/ListView.java
index 6532125d..f8a6f89 100644
--- a/core/java/android/widget/ListView.java
+++ b/core/java/android/widget/ListView.java
@@ -3264,9 +3264,13 @@
if (mChoiceMode == CHOICE_MODE_MULTIPLE) {
mCheckStates.put(position, value);
} else {
- boolean oldValue = mCheckStates.get(position, false);
+ // Clear the old value: if something was selected and value == false
+ // then it is unselected
mCheckStates.clear();
- if (!oldValue) {
+ // If value == true, select the appropriate position
+ // this may end up selecting the value we just cleared but this way
+ // we don't have to first to a get(position)
+ if (value) {
mCheckStates.put(position, true);
}
}