Hiding dialog with spinner
In my activity I create an own dialog with spinner and edit box. The problem I got was orientation change - I got exception each time, so:
1) I added android:configChanges="o开发者_运维技巧rientation|keyboardHidden"
in my activity's part in manifest.
2) Implemented onConfigurationChanged in my Activity, which more less look like this:
@Override
public void onConfigurationChange(Configuration newConfiguration) {
super.onConfigurationChange(newConfiguration);
if (mMyDialog != null && mMyDialog.isShowing() ) {
mMyDialog.dismiss();
}
Most times it works ok, but sometimes when I launch my dialog, activate Spinner (launch Spinners Pop-Up) and change orientation I got:
ERROR/AndroidRuntime(2928): at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:385) ERROR/AndroidRuntime(2928): at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:230) ERROR/AndroidRuntime(2928): at android.view.Window$LocalWindowManager.removeView(Window.java:432) ERROR/AndroidRuntime(2928): at android.app.Dialog.dismissDialog(Dialog.java:290) ERROR/AndroidRuntime(2928): at android.app.Dialog.access$000(Dialog.java:78) ERROR/AndroidRuntime(2928): at android.app.Dialog$1.run(Dialog.java:123) ERROR/AndroidRuntime(2928): at android.app.Dialog.dismiss(Dialog.java:280)
So it looks like the dialog is not dismissed on time ? Maybe I should override dismiss() method in MyDialog class and make sure all controls are 'closed' ? My dialog class is created as follows:
mMyDialog = new MyDialog(this);
mMyDialog.show();
May be you can try mMyDialog.hide(); function of dialog class
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. In my answer actually show how to restore spinner menu after orientation change, but you can easily choose not to do that.
with mMyDialog.hide()
, it beahaves the same.
I also add that this
in MyDialog
constructor is a Context
object.
精彩评论