From c854f281a1c330931a2a03eef802ad7d4521998e Mon Sep 17 00:00:00 2001 From: Adam Powell Date: Wed, 16 Dec 2009 14:11:53 -0800 Subject: [PATCH] Force a re-layout of children if ListView is out of sync with the adapter in onFocusChanged. Addresses bug 2157773 --- core/java/android/widget/ListView.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/core/java/android/widget/ListView.java b/core/java/android/widget/ListView.java index b574d45941aa0..e0d2ceffc8949 100644 --- a/core/java/android/widget/ListView.java +++ b/core/java/android/widget/ListView.java @@ -3080,13 +3080,19 @@ public class ListView extends AbsListView { if (gainFocus && previouslyFocusedRect != null) { previouslyFocusedRect.offset(mScrollX, mScrollY); + final ListAdapter adapter = mAdapter; + final int firstPosition = mFirstPosition; + // Don't cache the result of getChildCount here, it could change in layoutChildren. + if (adapter.getCount() < getChildCount() + firstPosition) { + mLayoutMode = LAYOUT_NORMAL; + layoutChildren(); + } + // figure out which item should be selected based on previously // focused rect Rect otherRect = mTempRect; int minDistance = Integer.MAX_VALUE; final int childCount = getChildCount(); - final int firstPosition = mFirstPosition; - final ListAdapter adapter = mAdapter; for (int i = 0; i < childCount; i++) { // only consider selectable views