显示简单信息的对话框 [英] Showing simple message dialogs
问题描述
在我的活动,我想显示简单信息的对话框,这样的东西:
新AlertDialog.Builder(上下文).setMessage(消息).show();
如果我这样做,对话框会泄漏,当我在旋转的手机(更不用提它会消失一样,所以用户可能会错过它)。我可以使用托管对话,但我不知道如何理智你使用这些类型的短消息?看起来你必须这样做:
的ShowDialog(SOME_DLG_ID);
...
@覆盖
onCreateDialog(INT ID){
如果(ID == SOME_DLG_ID){
新AlertDialog.Builder(上下文).setMessage(消息).show();
}
}
有没有办法通过什么样的信息应该是到onCreateDialog,因为它的覆盖方法。我讨厌做父母的活动,只是卖场无论当前消息应该是一个成员变量。你怎么都这样做?
感谢
如果我这样做,对话框会泄漏 当我转动那个电话(不 何况它会消失一样,所以 用户可能会错过它)
您可以添加
<活动
机器人:configChanges =方向| keyboardHidden
>
你的AndroidManifest.xml中以prevent重新启动该活动的电话旋转时。我使用它在我的应用程序,我的AlertDialog生存的手机的旋转。
In my activity, I'd like to show simple info dialogs, stuff like:
new AlertDialog.Builder(context).setMessage(message).show();
if I do that, the dialog will leak when I rotate that phone (not to mention it will disappear as well, so the user may miss it). I can use the managed dialogs, but I'm not sure how you use it sensibly for these types of short messages? Looks like you have to do this:
showDialog(SOME_DLG_ID);
...
@Override
onCreateDialog(int id) {
if (id == SOME_DLG_ID) {
new AlertDialog.Builder(context).setMessage(message).show();
}
}
there's no way to pass what the message should be into onCreateDialog since its an override method. I'd hate to make a member variable of the parent activity that just stores whatever the current message should be. How do you all do it?
Thanks
if I do that, the dialog will leak when I rotate that phone (not to mention it will disappear as well, so the user may miss it)
You can add
<activity
android:configChanges="orientation|keyboardHidden"
>
to your AndroidManifest.xml to prevent restarting the activity when the phone rotates. I am using it in my app and my AlertDialog survives the rotation of phone.
这篇关于显示简单信息的对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!