File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 3030import android .view .Gravity ;
3131import android .view .View ;
3232import android .view .ViewGroup ;
33+ import android .view .ViewTreeObserver ;
34+ import android .view .ViewTreeObserver .OnGlobalLayoutListener ;
3335import android .view .accessibility .AccessibilityEvent ;
3436import android .view .accessibility .AccessibilityNodeInfo ;
37+ import android .widget .PopupWindow .OnDismissListener ;
3538
3639
3740/**
@@ -978,6 +981,30 @@ public void show() {
978981 super .show ();
979982 getListView ().setChoiceMode (ListView .CHOICE_MODE_SINGLE );
980983 setSelection (Spinner .this .getSelectedItemPosition ());
984+
985+ // Make sure we hide if our anchor goes away.
986+ // TODO: This might be appropriate to push all the way down to PopupWindow,
987+ // but it may have other side effects to investigate first. (Text editing handles, etc.)
988+ final ViewTreeObserver vto = getViewTreeObserver ();
989+ if (vto != null ) {
990+ final OnGlobalLayoutListener layoutListener = new OnGlobalLayoutListener () {
991+ @ Override
992+ public void onGlobalLayout () {
993+ if (!Spinner .this .isVisibleToUser ()) {
994+ dismiss ();
995+ }
996+ }
997+ };
998+ vto .addOnGlobalLayoutListener (layoutListener );
999+ setOnDismissListener (new OnDismissListener () {
1000+ @ Override public void onDismiss () {
1001+ final ViewTreeObserver vto = getViewTreeObserver ();
1002+ if (vto != null ) {
1003+ vto .removeOnGlobalLayoutListener (layoutListener );
1004+ }
1005+ }
1006+ });
1007+ }
9811008 }
9821009 }
9831010}
You can’t perform that action at this time.
0 commit comments