What is the proper way to handle orientation change when a custom alertdialog has an open spinner?

前端 未结 3 1104
星月不相逢
星月不相逢 2021-01-05 13:42

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

3条回答
  •  醉酒成梦
    2021-01-05 14:25

    Ok, I think I've found your problem: dialog.dismiss();
    You are doing really strange thing - you are creating dialog through activity but say dismiss to it not to activity to dismiss it - those are two different approaches which you can't mix. You should choose one method: dialog.show and dialog.dismiss or activity.showDialog() and activity.dismissDialog() <- this is better because handles orientation change.
    What you should do is just remove dialog from class variables, use activity.showDialog everywhere. Probably your problem was in dismissing dialog in onClick. Just use YourActivityName.this.dismissDialog(DIALOG_NUMBER) and it should work.
    Read more about dialogs form developers site - I had also such problems and taken long time to learn how it works but after all - dialogs are not so complicated ;)

提交回复
热议问题