Android - 对话框关闭时应删除对话框中的条目
我有一个带有输入字段的自定义对话框。我希望在对话框关闭后(通过后退或按下某个按钮时)删除可能的条目,即不应保存状态。
我怎样才能做到这一点?
I have a customDialog with input fields. I want possible entries to be removed once the dialog is closed (either via back or when a certain button is pressed), i.e. the state should not be saved.
How can I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果按下后退按钮意味着对话框被
取消
。为您的对话框实现 DialogInterface.OnCancelListener 并清空/删除/清空您想要的条目。If the back button is pressed means that dialog is
canceled
. ImplementDialogInterface.OnCancelListener
for your dialog and empty/delete/null the entries you want.我想你可能会遇到另一个问题。
假设您显示了一个已关闭的对话框。如果第二次显示相同的对话框,则不会重建它。它只会再次显示。
这意味着,如果您在
onCreateDialog
方法中设置对话框,则第二次显示该对话框时,不会调用此方法!相反,onPrepareDialog
被调用。替代方案?您可以调用
Activity.removeDialog
或在onPrepareDialog
挂钩中处理设置过程。I think you might be getting another problem.
Say that you have shown a dialog which was dismissed. If the same dialog is going to be shown a second time, it won't be rebuilt. It will just be shown again.
This means that if you setup your dialog in the
onCreateDialog
method, the second time that the dialog is shown, this method isn't invoked! Instead,onPrepareDialog
is invoked.Alternatives? You can call
Activity.removeDialog
or take care of the setup process in theonPrepareDialog
hook.