@Override public void onGlobalLayout() { showPopup(); final ViewTreeObserver vto = getViewTreeObserver(); if (vto != null) vto.removeGlobalOnLayoutListener(this); } };
@SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override public void onDismiss() { final ViewTreeObserver vto = getViewTreeObserver(); if (vto != null) { if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) vto.removeOnGlobalLayoutListener(layoutListener); else vto.removeGlobalOnLayoutListener(layoutListener); } onPopupDismissed(); }
@Override public void onRestoreInstanceState(Parcelable state) { SavedState ss = (SavedState) state; super.onRestoreInstanceState(ss.getSuperState()); setSelection(ss.position); if (ss.showDropdown) { ViewTreeObserver vto = getViewTreeObserver(); if (vto != null) { final ViewTreeObserver.OnGlobalLayoutListener listener = new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { showPopup(); final ViewTreeObserver vto = getViewTreeObserver(); if (vto != null) vto.removeGlobalOnLayoutListener(this); } }; vto.addOnGlobalLayoutListener(listener); } } }
public void show() { final boolean wasShowing = isShowing(); computeContentWidth(); setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED); super.show(); if (wasShowing) { // Skip setting up the layout/dismiss listener below. If we were previously // showing it will still stick around. return; } // Make sure we hide if our anchor goes away. // TODO: This might be appropriate to push all the way down to PopupWindow, // but it may have other side effects to investigate first. (Text editing handles, etc.) final ViewTreeObserver vto = getViewTreeObserver(); if (vto != null) vto.addOnGlobalLayoutListener(layoutListener); } }