Spinner drop-down list and screen orientation change problem

后端 未结 3 2162
野性不改
野性不改 2020-12-19 14:03

I have a problem with a spinner drop down list and changing orientations.

In my activity, I display a dialog in which I have two spinners. When the dialog is shown t

3条回答
  •  一个人的身影
    2020-12-19 14:51

    This occurs because onDetachedFromWindow() does not get called on the spinner when dialog.dismiss() is called. The solution for this is to create a simple custom spinner class the exposes this method.

     public class DialogSpinner extends Spinner {
    
         public DialogSpinner(Context context, AttributeSet attrs) {
             super(context, attrs);
         }
    
         @Override
         public void onDetachedFromWindow() {
             super.onDetachedFromWindow();
         }
     }
    

    Now the onDetachedFromWindow() method is publicly available. Then in your dialog class override the onPause() method.

     @Override
     public void onPause() {
         mYourSpinner.onDetachedFromWindow();
         super.onPause();
     }
    

    It's definately a workaround, but it seems to do the trick.

提交回复
热议问题