diff options
| author | Adam Powell <adamp@google.com> | 2010-08-13 18:27:04 -0700 |
|---|---|---|
| committer | Adam Powell <adamp@google.com> | 2010-08-16 11:05:57 -0700 |
| commit | f343e1ba7e796120eefa917dbf78348feea98e11 (patch) | |
| tree | f69d0281bcf2f8c2b3ab0ae864b64ea552f1d5a9 /core/java/android/widget/GridView.java | |
| parent | fed762b944efb690b10ca2705f02343dda0aab03 (diff) | |
Add selection mode support to GridView.
Changed 9.xml to make update-api behave with the API change involved.
Several fields and methods moved from ListView to AbsListView. This
should not break source or binary compatibility.
Change-Id: Icad6e238522b8b7cc5bbc935ad89ac3e015572c1
Diffstat (limited to 'core/java/android/widget/GridView.java')
| -rw-r--r-- | core/java/android/widget/GridView.java | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/core/java/android/widget/GridView.java b/core/java/android/widget/GridView.java index a5b3ed5bfc7c..ea767f676317 100644 --- a/core/java/android/widget/GridView.java +++ b/core/java/android/widget/GridView.java @@ -104,6 +104,26 @@ public class GridView extends AbsListView { a.recycle(); } + /** + * Set how the user may select items from the grid. + * + * <p>GridView only supports {@link AbsListView#CHOICE_MODE_NONE} and + * {@link AbsListView#CHOICE_MODE_MULTIPLE_MODAL}. Attempting to set an unsupported choice + * mode will throw an UnsupportedOperationException. + */ + @Override + public void setChoiceMode(int choiceMode) { + switch (choiceMode) { + case CHOICE_MODE_NONE: + case CHOICE_MODE_MULTIPLE_MODAL: + super.setChoiceMode(choiceMode); + break; + + default: + throw new UnsupportedOperationException("Unsupported choice mode " + choiceMode); + } + } + @Override public ListAdapter getAdapter() { return mAdapter; @@ -136,7 +156,10 @@ public class GridView extends AbsListView { mOldSelectedPosition = INVALID_POSITION; mOldSelectedRowId = INVALID_ROW_ID; - + + // AbsListView#setAdapter will update choice mode states. + super.setAdapter(adapter); + if (mAdapter != null) { mOldItemCount = mItemCount; mItemCount = mAdapter.getCount(); @@ -1312,6 +1335,12 @@ public class GridView extends AbsListView { child.setPressed(isPressed); } + if (mChoiceMode != CHOICE_MODE_NONE && mCheckStates != null) { + if (child instanceof Checkable) { + ((Checkable) child).setChecked(mCheckStates.get(position)); + } + } + if (needToMeasure) { int childHeightSpec = ViewGroup.getChildMeasureSpec( MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), 0, p.height); |
