In my app I have a custom AlertDialog (handled by the system using showDialog()) which contains a tabhost with 2 tabs. In one of the tabs is a spinner. I can rotate my scr
I found a better solution. It is actually not so hard to replace Spinner with a button that looks and behaves like Spinner (except the crash, fortunately).
public void showSpinner() {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle(_spinnerPrompt);
builder.setSingleChoiceItems(_spinnerOptions, _spinnerSelection,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int item) {
_spinnerSelection = item;
_pseudoSpinner.setText(_spinnerOptions[item]);
_restoreSpinnerOnRestart = false;
dialog.dismiss();
}
});
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
_restoreSpinnerOnRestart = false;
}
});
AlertDialog alert = builder.create();
_restoreSpinnerOnRestart = true;
alert.show();
}
@Override
public Bundle onSaveInstanceState() {
Bundle state = super.onSaveInstanceState();
state.putBoolean(STATE_SPINNER_RESTORE, _restoreSpinnerOnRestart);
state.putInt(STATE_SPINNER_SELECTION, _spinnerSelection);
return state;
};
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
_spinnerSelection = savedInstanceState.getInt(STATE_SPINNER_SELECTION, -1);
_restoreSpinnerOnRestart = savedInstanceState.getBoolean(STATE_SPINNER_RESTORE);
_pseudoSpinner.setText(_spinnerOptions[_spinnerSelection]);
if (_restoreSpinnerOnRestart) {
showSpinner();
}
};