summaryrefslogtreecommitdiffstats
path: root/core/java
diff options
context:
space:
mode:
authorGilles Debunne <debunne@google.com>2010-02-18 10:26:34 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-02-18 10:26:34 -0800
commitd651629478ea4615e3a493aa63ae455d6fefb38f (patch)
treea3790069d506d2bdd5b63c07c5a76330d04c53b3 /core/java
parentd7a0cdee1df15719fb47e33d3cc98043324d9b5e (diff)
parentfd3ddfa6f0559eb29eea179690144a7357c34b3d (diff)
downloadframeworks_base-d651629478ea4615e3a493aa63ae455d6fefb38f.zip
frameworks_base-d651629478ea4615e3a493aa63ae455d6fefb38f.tar.gz
frameworks_base-d651629478ea4615e3a493aa63ae455d6fefb38f.tar.bz2
Merge "List.GetCheckItemIds no longer includes unchecked items."
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/widget/ListView.java46
1 files changed, 30 insertions, 16 deletions
diff --git a/core/java/android/widget/ListView.java b/core/java/android/widget/ListView.java
index c428dc0..5308725 100644
--- a/core/java/android/widget/ListView.java
+++ b/core/java/android/widget/ListView.java
@@ -16,14 +16,17 @@
package android.widget;
+import com.android.internal.R;
+import com.google.android.collect.Lists;
+
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
-import android.graphics.Rect;
-import android.graphics.PixelFormat;
import android.graphics.Paint;
-import android.graphics.drawable.Drawable;
+import android.graphics.PixelFormat;
+import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
+import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
@@ -31,16 +34,13 @@ import android.util.SparseBooleanArray;
import android.view.FocusFinder;
import android.view.KeyEvent;
import android.view.MotionEvent;
+import android.view.SoundEffectConstants;
import android.view.View;
import android.view.ViewDebug;
import android.view.ViewGroup;
import android.view.ViewParent;
-import android.view.SoundEffectConstants;
import android.view.accessibility.AccessibilityEvent;
-import com.google.android.collect.Lists;
-import com.android.internal.R;
-
import java.util.ArrayList;
/*
@@ -2722,7 +2722,8 @@ public class ListView extends AbsListView {
/**
* Determine the distance to the nearest edge of a view in a particular
- * direciton.
+ * direction.
+ *
* @param descendant A descendant of this list.
* @return The distance, or 0 if the nearest edge is already on screen.
*/
@@ -3307,9 +3308,9 @@ public class ListView extends AbsListView {
* Sets the checked state of the specified position. The is only valid if
* the choice mode has been set to {@link #CHOICE_MODE_SINGLE} or
* {@link #CHOICE_MODE_MULTIPLE}.
- *
+ *
* @param position The item whose checked state is to be checked
- * @param value The new checked sate for the item
+ * @param value The new checked state for the item
*/
public void setItemChecked(int position, boolean value) {
if (mChoiceMode == CHOICE_MODE_NONE) {
@@ -3392,10 +3393,11 @@ public class ListView extends AbsListView {
}
/**
- * Returns the set of checked items ids. The result is only valid if
- * the choice mode has not been set to {@link #CHOICE_MODE_SINGLE}.
- *
- * @return A new array which contains the id of each checked item in the list.
+ * Returns the set of checked items ids. The result is only valid if the
+ * choice mode has not been set to {@link #CHOICE_MODE_SINGLE}.
+ *
+ * @return A new array which contains the id of each checked item in the
+ * list.
*/
public long[] getCheckItemIds() {
if (mChoiceMode != CHOICE_MODE_NONE && mCheckStates != null && mAdapter != null) {
@@ -3404,11 +3406,23 @@ public class ListView extends AbsListView {
final long[] ids = new long[count];
final ListAdapter adapter = mAdapter;
+ int checkedCount = 0;
for (int i = 0; i < count; i++) {
- ids[i]= adapter.getItemId(states.keyAt(i));
+ if (states.valueAt(i)) {
+ ids[checkedCount++] = adapter.getItemId(states.keyAt(i));
+ }
}
- return ids;
+ // Trim array if needed. mCheckStates may contain false values
+ // resulting in checkedCount being smaller than count.
+ if (checkedCount == count) {
+ return ids;
+ } else {
+ final long[] result = new long[checkedCount];
+ System.arraycopy(ids, 0, result, 0, checkedCount);
+
+ return result;
+ }
}
return new long[0];