diff options
| author | 2011-08-08 23:29:12 -0700 | |
|---|---|---|
| committer | 2011-08-08 23:50:25 -0700 | |
| commit | b3750133db256ffa5956c8836bc86c3c22918cb1 (patch) | |
| tree | cdf14c75732948f879c4008c6d012b1c4bfc4507 | |
| parent | 3a02ff1300772b0063a7a97ffc0248275603fe7c (diff) | |
Fix bug 5135608 - Let AbsListView take focus while detached
While it is valid to request focus while detached from a window,
AbsListView did not handle it gracefully if it had an adapter whose
data changed while the view was detached, since DataSetObservers are
unregistered during this time. Assume that the data could have changed
if we gain focus while detached.
Change-Id: Id135693ffcc48ff5a9d530d335ab449180624c43
| -rw-r--r-- | core/java/android/widget/AbsListView.java | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java index 9737a5a9bc07..db4df40a43b5 100644 --- a/core/java/android/widget/AbsListView.java +++ b/core/java/android/widget/AbsListView.java @@ -632,6 +632,11 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te private int mLastAccessibilityScrollEventToIndex; /** + * Track if we are currently attached to a window. + */ + private boolean mIsAttached; + + /** * Interface definition for a callback to be invoked when the list or grid * has been scrolled. */ @@ -1665,6 +1670,13 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) { super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); if (gainFocus && mSelectedPosition < 0 && !isInTouchMode()) { + if (!mIsAttached && mAdapter != null) { + // Data may have changed while we were detached and it's valid + // to change focus while detached. Refresh so we don't die. + mDataChanged = true; + mOldItemCount = mItemCount; + mItemCount = mAdapter.getCount(); + } resurrectSelection(); } } @@ -2334,6 +2346,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te mOldItemCount = mItemCount; mItemCount = mAdapter.getCount(); } + mIsAttached = true; } @Override @@ -2388,6 +2401,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te removeCallbacks(mTouchModeReset); mTouchModeReset = null; } + mIsAttached = false; } @Override |