views:

165

answers:

1

I am validating an AlertDialog, and I would like to raise a Toast on top of the AlertDialog display.

I have this code, but the Toast is displayed on the activity

new AlertDialog.Builder(this).setTitle(R.string.contact_groups_add)
                .setView(addView).setPositiveButton(R.string.ok,
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int whichButton) {

                                if (wrapper.getTitle().length()>0)
                                {
                                    processAdd(wrapper);
                                } else {
                                    Toast.makeText(getApplicationContext(), "Name is required", Toast.LENGTH_SHORT).show();
                                }
                            }
                        }).setNegativeButton(R.string.cancel,
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int whichButton) {
                                // ignore, just dismiss
                            }
                        }).show();
+3  A: 

Instead of using AdvertDialog.Builder, you can create a custom dialog which will behave like a dialog, but is in fact a normal activity. Your toasts should be drawn normally on top of this.

seanhodges
That is the best way to do it I'd imagane, the AlertDialog builder builds the Dialog as part of the activity so the toast appears on the activity then, at least thats what i believe happens
Donal Rafferty
Yeah that happens, so isn't possible to raise on top of the alertdialog?
Pentium10
I don't think the AlertDialog.Builder gives you that level of control. It is a convenience method for writing simple dialogs, if you need something more specific then usually you write your own dialog activity.
seanhodges