I have an alert dialog with an EditText in it and I'd like to warn the user when the entered input text is empty. So either : - by opening a new alert dialog on the top of the current one, but without closing the current one. I tried it and I don't know how to it. - by changing dynamically the message on my alert dialog, but again I don't how
Asked
Active
Viewed 4,959 times
2 Answers
2
Try giving this a shot:
Toast.makeText(this, "You have entered an empty string, silly!", Toast.LENGTH_SHORT).show();
It's just a simple popup dialog but it should suffice for your needs. You can change 'Toast.LENGTH_SHORT' to 'Toast.LENGTH_LONG' depending on how long you want the dialog to stay visible, after which it will fade away into oblivion.
Or for a more comprehensive solution:
public void alertMessage(string Message)
{
Toast.makeText(this, Message, Toast.LENGTH_SHORT).show();
}

Frank Allenby
- 4,332
- 1
- 17
- 17
1
You could do what you want when you set the buttons for your AlertDialog
like:
.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //Here check to see if you have an empty EditText and take appropriate measures } })

user
- 86,916
- 18
- 197
- 190
-
That's exactly what I'm trying to achieve but I can't prevent the alert dialog from being closed. That's actually my main problem. – thomaus Sep 13 '11 at 12:29
-
Ok, I found how to do it. There is no other way than creating a custom alert dialog. – thomaus Sep 13 '11 at 13:33