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
1 file changed