diff options
author | Adam Cohen <adamcohen@google.com> | 2010-09-08 14:19:39 -0700 |
---|---|---|
committer | Adam Cohen <adamcohen@google.com> | 2010-09-08 14:58:16 -0700 |
commit | bd0136a2fde1d81a835f94efe3193569b10d99ff (patch) | |
tree | 16772813b93ca0a49ade7b55926ae8f703d5ceac /core | |
parent | 467e8e13327bd9ad2dbabfa0a9b31f860202c7b1 (diff) | |
download | frameworks_base-bd0136a2fde1d81a835f94efe3193569b10d99ff.zip frameworks_base-bd0136a2fde1d81a835f94efe3193569b10d99ff.tar.gz frameworks_base-bd0136a2fde1d81a835f94efe3193569b10d99ff.tar.bz2 |
AdapterViewAnimator now properly handles notifyDataSetChanged
Change-Id: Icc22671b76d49c4229f118f77a5c269253a07b84
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/widget/AdapterViewAnimator.java | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/core/java/android/widget/AdapterViewAnimator.java b/core/java/android/widget/AdapterViewAnimator.java index e8d96c5..052a38a 100644 --- a/core/java/android/widget/AdapterViewAnimator.java +++ b/core/java/android/widget/AdapterViewAnimator.java @@ -339,6 +339,25 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter> return new ViewGroup.LayoutParams(0, 0); } + private void refreshChildren() { + for (int i = mCurrentWindowStart; i <= mCurrentWindowEnd; i++) { + int index = modulo(i, mNumActiveViews); + + // get the fresh child from the adapter + View updatedChild = mAdapter.getView(i, null, this); + + if (mActiveViews[index] != null) { + FrameLayout fl = (FrameLayout) mActiveViews[index]; + // flush out the old child + fl.removeAllViewsInLayout(); + // add the new child to the frame, if it exists + if (updatedChild != null) { + fl.addView(updatedChild); + } + } + } + } + void showOnly(int childIndex, boolean animate, boolean onLayout) { if (mAdapter == null) return; @@ -414,16 +433,19 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter> // We've cleared a spot for the new view. Get it from the adapter, add it // and apply any transform / animation View newView = mAdapter.getView(i, null, this); + + // We wrap the new view in a FrameLayout so as to respect the contract + // with the adapter, that is, that we don't modify this view directly + FrameLayout fl = new FrameLayout(mContext); + + // If the view from the adapter is null, we still keep an empty frame in place if (newView != null) { - // We wrap the new view in a FrameLayout so as to respect the contract - // with the adapter, that is, that we don't modify this view directly - FrameLayout fl = new FrameLayout(mContext); - fl.addView(newView); - mActiveViews[index] = fl; - addChild(fl); - applyTransformForChildAtIndex(fl, newRelativeIndex); - animateViewForTransition(-1, newRelativeIndex, fl); + fl.addView(newView); } + mActiveViews[index] = fl; + addChild(fl); + applyTransformForChildAtIndex(fl, newRelativeIndex); + animateViewForTransition(-1, newRelativeIndex, fl); } mActiveViews[index].bringToFront(); } @@ -523,10 +545,12 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter> // if the data changes, mWhichChild might be out of the bounds of the adapter // in this case, we reset mWhichChild to the beginning - if (mWhichChild >= mAdapter.getCount()) + if (mWhichChild >= mAdapter.getCount()) { mWhichChild = 0; - showOnly(mWhichChild, true, true); + showOnly(mWhichChild, true, true); + } + refreshChildren(); } final int childCount = getChildCount(); |