Hi,

My application throws a dialog with an OK button and some error
message every time an error is encountered while processing user
input. For example, on one screen user should enter some information
into two text boxes (say text1 and text2) and hit a save button. In
the save button click handler I check if text1 is empty (among other
checks) I thrown a dialog with appropriate message (says msg1) and a
OK button to give user a chance to correct the error. Then if user
fills in text1 but not text2, I throw another dialog with a different
message (say msg2) and a OK button. What I am seeing is that when both
text1 and text2 are left empty and save button is hit,  a dialog is
seen with msg1. When I click ok and fill in the textbox1 but not
textbox2 and click save button, I expect to see another dialog with
msg2. But what I am seeing is dialog with msg1 itself. So, the old
dialog is being shown instead of new dialog. I am not sure whether
this is expected behavior or whether it has anything to do with the
way I create the AlertDialog. Here is the relevant code.

  String alertString;           // global variable in this activity class

        saveButton = (Button) findViewById(R.id.save);
        saveButton.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                        saveButtonHandler();
                }
        });


private void saveButtonHandler() {
       ....
       ....
        Log.e("MYAPP1:  ", "Message1 Length = " +
Msg1.getText().toString().length());
        if (Msg1.getText().toString().length() == 0) {
                /* throw an error message to the user */
                Log.e("MYAPP1: ", "Message1 cannot be empty");
                alertString = "Message1 cannot be empty";
                showDialog(ERROR_DIALOG_ID);
                return;
        }

        Log.e("MYAPP1:  ", "Message2 Length = " +
Msg2.getText().toString().length());
        if (Msg2.getText().toString().length() == 0) {
                /* throw an error message to the user */
                Log.e("MYAPP1: ", "Message2 cannot be empty");
                alertString = "Message2 cannot be empty";
                showDialog(ERROR_DIALOG_ID);
                return;
        }
        ....
        ....
}

   protected Dialog onCreateDialog(int id) {
        AlertDialog alertDialog;
        
        switch (id) {
        case ERROR_DIALOG_ID:
                alertDialog = new AlertDialog.Builder(this).create();
                alertDialog.setMessage(alertString);
                alertDialog.setButton("OK", new 
DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        // ((AlertDialog)dialog).setMessage("");  ---> this
didn't work either
                            return;
                    }
                });
                return alertDialog;
        }
        return null;
    }

Thanks,
Sarath

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to