diff options
author | Mark Brophy <mbrophy@google.com> | 2011-08-01 16:24:44 +0100 |
---|---|---|
committer | Mark Brophy <mbrophy@google.com> | 2011-08-01 16:32:03 +0100 |
commit | 1ea6889136cdad8fc01de0665b3a16a4dcb259fe (patch) | |
tree | 200f54117167ee5fac6607b0b55f035744262a6d | |
parent | ae65c17959042edd5f1b44e7653d1a775bbfceec (diff) | |
download | frameworks_base-1ea6889136cdad8fc01de0665b3a16a4dcb259fe.zip frameworks_base-1ea6889136cdad8fc01de0665b3a16a4dcb259fe.tar.gz frameworks_base-1ea6889136cdad8fc01de0665b3a16a4dcb259fe.tar.bz2 |
Fix exception when a focused item is detached.
When a ListView has itemsCanFocus set, and scrolling moves the currently
focused item off the display, its focus is cleared. This is checked by
calling getDistanceToView().
However, it's possible that the view will have been recycled. If so, it
will have been detached from the parent by calling
ViewGroup.detachViewFromParent. Since this doesn't clear the view's
focus, we'll still try to call getDistanceFromView(), causing an
IllegalArgumentException since the view is not a descendant of the
ListView anymore.
Check whether the view is still a descendant before calling
getDistanceToView(). If it's not, we also need to clear the focus.
Bug: 4556022
Change-Id: Iebee56032223b70d714e2ec3bb7a19093ab5f81c
-rw-r--r-- | core/java/android/widget/ListView.java | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/core/java/android/widget/ListView.java b/core/java/android/widget/ListView.java index 1f29b16..946f009 100644 --- a/core/java/android/widget/ListView.java +++ b/core/java/android/widget/ListView.java @@ -2428,7 +2428,7 @@ public class ListView extends AbsListView { if (mItemsCanFocus && (focusResult == null) && selectedView != null && selectedView.hasFocus()) { final View focused = selectedView.findFocus(); - if (distanceToView(focused) > 0) { + if (!isViewAncestorOf(focused, this) || distanceToView(focused) > 0) { focused.clearFocus(); } } |