tags:

views:

515

answers:

2

I have a class that extends android.app.Dialog, the layout is done in an xml file, and the setup (button listeners, etc) is done on the onCreate method. My problem is that whenever the dialog is displayed, then dismissed, and displayed again, the Editable TextViews are still populated with the information that was displayed previously. What is the common way to clear these text fields? Remember - this is a separate class that extends Dialog - so there is no 'onDialogCreate' like Activity has.

Or, perhaps I am extending the wrong class? There is just a lot of processing being done, and do not want to have all the code in the main Activity. I would like it to be in a separate Class. I tried to extend AlertDialog, but it does not create the border like Dialog does. Any help would be great.

The dialog is shown via the Activity:

    protected Dialog onCreateDialog(int id) {
        switch(id){
            case DIALOG_NEW_SAFE:
                return(new NewSafeDialog(this));
            default:
                return(null);
        }
    }
A: 

Try clearing the text in the constructor of the NewSafeDialog i.e. your dialog class.

Karan
+1  A: 

onCreateDialog(..) caches the dialog which means the same instance is reused.

3 ways to fix the undesired behavior off my head:

  1. Override onPrepareDialog(..), use findViewById(..) to get whatever you want to clear, clear it.
  2. Don't rely on managed dialogs at all, do new NewSafeDialog(this).show() each time you want to show the dialog.
  3. Add onCancelListener(..), onDismissListener(..) inside your custom dialog that would call a method to clear itself.
alex