I have an alert dialog with an EditText in it and开发者_如何学Go 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
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();
}
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 } })
精彩评论