From a31d4edb7498956050e7c01b628ace9483e89164 Mon Sep 17 00:00:00 2001 From: "tianran.x.li" Date: Mon, 28 Nov 2016 15:34:24 +0800 Subject: [PATCH] Skip ListPopupWindow position update if detached Symptom: A part of the option is displayed in the wrong location. Root cause: When the search item is clicked, the menu item will be hidden. The PopupWindow will be detached from window and the mAttachInfo property will be set to null. The anchor coordinates will return x 0 and y 0. Solution: If the anchor view is detached from window, the ListPopupWindow will not be update. Bug: 36207919 Change-Id: I2b370c31542fae454592463e12313fdeaef25afe --- core/java/android/widget/ListPopupWindow.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/java/android/widget/ListPopupWindow.java b/core/java/android/widget/ListPopupWindow.java index 6a10743c1c56a..203b8dd7fc405 100644 --- a/core/java/android/widget/ListPopupWindow.java +++ b/core/java/android/widget/ListPopupWindow.java @@ -600,6 +600,10 @@ public class ListPopupWindow implements ShowableListMenu { mPopup.setWindowLayoutType(mDropDownWindowLayoutType); if (mPopup.isShowing()) { + if (!getAnchorView().isAttachedToWindow()) { + //Don't update position if the anchor view is detached from window. + return; + } final int widthSpec; if (mDropDownWidth == ViewGroup.LayoutParams.MATCH_PARENT) { // The call to PopupWindow's update method below can accept -1 for any