summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Powell <adamp@google.com>2013-09-10 11:38:52 -0700
committerAdam Powell <adamp@google.com>2013-09-10 11:38:52 -0700
commit6a221b3f85fbe7cbfbd11b9eeb672baca27faec2 (patch)
treeb34404cdcd2aa55d184f1415e6af9f845231349b
parentba85b970f3ae7fd58c9a631e64bff0d05b787b9b (diff)
downloadframeworks_base-6a221b3f85fbe7cbfbd11b9eeb672baca27faec2.zip
frameworks_base-6a221b3f85fbe7cbfbd11b9eeb672baca27faec2.tar.gz
frameworks_base-6a221b3f85fbe7cbfbd11b9eeb672baca27faec2.tar.bz2
Fix some bizarre Spinner behavior
* Make sure the recycler is cleared when the adapter is changed. Bug 10689596 * Don't add views to measure the baseline. Bug 10690353 Change-Id: I841dc05652eef3319721631f96332f7900d1a631
-rw-r--r--core/java/android/widget/Spinner.java24
1 files changed, 14 insertions, 10 deletions
diff --git a/core/java/android/widget/Spinner.java b/core/java/android/widget/Spinner.java
index b87ed7a..b75d36f 100644
--- a/core/java/android/widget/Spinner.java
+++ b/core/java/android/widget/Spinner.java
@@ -412,6 +412,8 @@ public class Spinner extends AbsSpinner implements OnClickListener {
public void setAdapter(SpinnerAdapter adapter) {
super.setAdapter(adapter);
+ mRecycler.clear();
+
if (mPopup != null) {
mPopup.setAdapter(new DropDownAdapter(adapter));
} else {
@@ -426,9 +428,8 @@ public class Spinner extends AbsSpinner implements OnClickListener {
if (getChildCount() > 0) {
child = getChildAt(0);
} else if (mAdapter != null && mAdapter.getCount() > 0) {
- child = makeAndAddView(0);
+ child = makeView(0, false);
mRecycler.put(0, child);
- removeAllViewsInLayout();
}
if (child != null) {
@@ -536,7 +537,7 @@ public class Spinner extends AbsSpinner implements OnClickListener {
mFirstPosition = mSelectedPosition;
if (mAdapter != null) {
- View sel = makeAndAddView(mSelectedPosition);
+ View sel = makeView(mSelectedPosition, true);
int width = sel.getMeasuredWidth();
int selectedOffset = childrenLeft;
final int layoutDirection = getLayoutDirection();
@@ -571,17 +572,17 @@ public class Spinner extends AbsSpinner implements OnClickListener {
* from the old to new positions.
*
* @param position Position in the spinner for the view to obtain
- * @return A view that has been added to the spinner
+ * @param addChild true to add the child to the spinner, false to obtain and configure only.
+ * @return A view for the given position
*/
- private View makeAndAddView(int position) {
-
+ private View makeView(int position, boolean addChild) {
View child;
if (!mDataChanged) {
child = mRecycler.get(position);
if (child != null) {
// Position the view
- setUpChild(child);
+ setUpChild(child, addChild);
return child;
}
@@ -591,7 +592,7 @@ public class Spinner extends AbsSpinner implements OnClickListener {
child = mAdapter.getView(position, null, this);
// Position the view
- setUpChild(child);
+ setUpChild(child, addChild);
return child;
}
@@ -601,8 +602,9 @@ public class Spinner extends AbsSpinner implements OnClickListener {
* and fill out its layout paramters.
*
* @param child The view to position
+ * @param addChild true if the child should be added to the Spinner during setup
*/
- private void setUpChild(View child) {
+ private void setUpChild(View child, boolean addChild) {
// Respect layout params that are already in the view. Otherwise
// make some up...
@@ -611,7 +613,9 @@ public class Spinner extends AbsSpinner implements OnClickListener {
lp = generateDefaultLayoutParams();
}
- addViewInLayout(child, 0, lp);
+ if (addChild) {
+ addViewInLayout(child, 0, lp);
+ }
child.setSelected(hasFocus());
if (mDisableChildrenWhenDisabled) {