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
The answer is here: app crashes when alert dialog is open and phone(emulator) changes its orientation . Look at answer from MegaMind to help resolve this.
I had an idea to prevent orientation changes when dialog with spinner is displayed, but found that there is no reliable way to do that. The best solution that I found is to replace spinner with a button.
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.