onCreateDialog 和动态对话框 (Android)
我有一个小问题。在我的程序中,我定义
protected Dialog onCreateDialog(int id) {
if (id == CONTEXT_MENU_ID) {
return createMyDialog();
}
return super.onCreateDialog(id);
}
并显示调用的对话框
showDialog(CONTEXT_MENU_ID)
我的问题是有时我想在执行之间动态更改对话框的文本。但使用这种方法,对话框永远不会被重新创建。如何在显示对话框之前调用 createMyDialog()?
谢谢
I have a little problem. In my program I defined
protected Dialog onCreateDialog(int id) {
if (id == CONTEXT_MENU_ID) {
return createMyDialog();
}
return super.onCreateDialog(id);
}
and then show the dialog calling
showDialog(CONTEXT_MENU_ID)
My problem is that sometimes I want to change the texts of the Dialog dynamically between executions. But with that method the Dialog is never recreated. How can I make the createMyDialog() to be called before showing the Dialog?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想更改对话框设置(文本等),您需要在 onPrepareDialogMethod 每次调用
showDialog
方法时都会调用它If you want to change dialog settings (text, etc.) you need to do it in onPrepareDialogMethod it will be called each time you call
showDialog
method这可能值得一试。我还没有测试过。对于对话框,如果您将textview设置为其内容,那么您可以为其设置一个id。
因此,下次当您尝试更新 textview 时,您也许可以使用 id 访问它。
This might be worth a try. I haven't tested it out. To the dialog if you set the textview as its content, then you can set an id to it.
So the next time when you try to update the textview, you might be able to access it using the id.