From 845df82084a0d3b14cdfb5baafea5c6b94967117 Mon Sep 17 00:00:00 2001 From: Brett Chabot Date: Mon, 3 Aug 2009 16:40:02 -0700 Subject: [PATCH] ListView.setItemChecked(p, false) always clears all items. 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 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/java/android/widget/ListView.java b/core/java/android/widget/ListView.java index 515b58117501..02a137ddff0a 100644 --- a/core/java/android/widget/ListView.java +++ b/core/java/android/widget/ListView.java @@ -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); } -- 2.11.0