views:

29

answers:

1

I want to create a dialog with a string that I build at runtime. It looks like API level 8 allows you to call showDialog with a bundle, but I have to write an app that will run on the older OSs.

How do I create a dialog with something like a simple error string and make sure it doesn't die when I rotate the screen.

I realize if I override onCreateDialog, it will do it for me. The problem is, this just takes the int constant. I need to pass a string to it so it knows what to put in the dialog.

If I build my dialog myself and then call .show() on it, it won't live through a screen orientation change.

A: 

You could just pass the string in the constructor.

public class MyDialog extends Dialog {

    public MyDialog(Context context, String msg) {
        super(context);
        TextView textView = new TextView(context);
        textView.setText(msg);
        setContentView(textView);
    }

}
Andy
The problem is I can't pass the string into the showDialog(int). If I'm in a method that makes calls to something like a web service and it returns to me an error message, how do I get that error message into MyDialog? If I call showDialog(int), all I can do is pass the dialogs identifier. I don't want to do something hacky like push the error message into a static string and hope that it's still OK when onCreateDialog is fired so that it can pick up the string. If I create my own dialog and then call show() on it, it won't get recreated after a screen orientation change unless I stash it.
zoonsf