diff options
author | Romain Guy <> | 2009-04-01 11:46:43 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-04-01 11:46:43 -0700 |
commit | ad28bed52ccabd252149b5297a2d94bacdb388cc (patch) | |
tree | 83eaa96dd3b6dad1c9f4d0d3f62de88700783a8c /core | |
parent | 096f41d53909a9ef68cb5d6f06524212e96c43b6 (diff) | |
download | frameworks_base-ad28bed52ccabd252149b5297a2d94bacdb388cc.zip frameworks_base-ad28bed52ccabd252149b5297a2d94bacdb388cc.tar.gz frameworks_base-ad28bed52ccabd252149b5297a2d94bacdb388cc.tar.bz2 |
AI 144042: Fixes #1742109. Add a new API to ListView to return the list of checked items ids.
BUG=1742109
Automated import of CL 144042
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/widget/ListView.java | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/core/java/android/widget/ListView.java b/core/java/android/widget/ListView.java index c84be0f..1daee4e 100644 --- a/core/java/android/widget/ListView.java +++ b/core/java/android/widget/ListView.java @@ -3220,6 +3220,29 @@ 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. + */ + public long[] getCheckItemIds() { + if (mChoiceMode != CHOICE_MODE_NONE && mCheckStates != null && mAdapter != null) { + final SparseBooleanArray states = mCheckStates; + final int count = states.size(); + final long[] ids = new long[count]; + final ListAdapter adapter = mAdapter; + + for (int i = 0; i < count; i++) { + ids[i]= adapter.getItemId(states.keyAt(i)); + } + + return ids; + } + + return new long[0]; + } + + /** * Clear any choices previously set */ public void clearChoices() { |