重置一个Android对话 [英] Reset an Android Dialog

查看:201
本文介绍了重置一个Android对话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了很多的话题如何保存对话的状态,例如用捆绑的实例。
不过,我似乎无法找到如何正确重置对话框。

I found plenty of topics on how to save states of a dialog, for instance using Bundle instances. However, I can't seem to find how to "properly" reset a dialog.

考虑这个样定制对话框(在XML布局进行ID为INPUT_TEXT一个EditText):

Consider this sample custom dialog (the XML layout carries an EditText with ID "input_text"):

public class CustomDialog extends Dialog {
  public CustomDialog (Context context) { super (context); }

  protected onCreate (Bundle savedInstanceState) {
    super.onCreate (savedInstanceState);

    setContentView(R.layout.input_query);
    EditText txt = (EditText) findViewById(R.id.input_text);

    // Consider that I'm declaring here the use of listeners
    // in order to retrieve input text.
  }
}

当被点击的主要活动的一个按钮,我弹出这个对话框。这个动作发生第二次,我的EditText包含从previous实例的输入。

I'm popping up this dialog when a button is clicked in the main Activity. The second time this action occurs, my EditText contains the input from the previous instance.

现在,我知道我可以重置此的EditText的内容,但我不知道是否有做到这一点,对话范围的一个通用的,已经existant方法。举例来说,如果我有一个更复杂的对话,我想它有默认值,这每一个对象实例的时间。我想删除调用 super.onCreate(savedInstanceState); 可以做的伎俩,但它不会

Now, I know I can reset the content of this EditText, but I'm wondering if there is a common, already existant method to do this, dialog-wide. For instance if I have a more complex dialog, I want that it has "default" values each time this object is instantiated. I thought removing the call tosuper.onCreate(savedInstanceState); could do the trick, but it does not.

很抱歉,如果这是一个愚蠢的问题(或者,如果已经解决...我没有找到它)...任何帮助是AP preciated。非常感谢!

Sorry if this is a silly question (or if already addressed... I did not find it)... Any help is appreciated. Thanks a lot!

推荐答案

通常你应该重写 onCreateDialog 上prepareDialog 方法。

Normally you should override onCreateDialog and onPrepareDialog methods of the activity.

第一次创建对话框中, onCreateDialog 被调用,所以你应该在这个方法创建对话框。要初始化/更新对话框覆盖在prepareDialog 的内容,它总是呈现出对话框之前调用。

For the first time creation of dialogs, onCreateDialog is called, so you should create your dialog in this method. To initialize/update the contents of dialogs override onPrepareDialog, it is always called before showing a dialog.

这篇关于重置一个Android对话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆