• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Can't check the value of an EditText in an AlertDialog

vovs

Newbie
Hi, folks!

I'm trying to check the value of the EditText inside my AlertDialog, so that I can prevent the user from entering nothing in the EditText.
For some reason, when I use the code below and press ok I return to List, but i want after "Name required" dialog leave in "Rename Contact" dialog.

Code:
case Constants.RENAME_CONTACT:
 AlertDialog dialog = new AlertDialog.Builder(context)
    		.setTitle("Rename Contact")
			.setMessage("Rename Contact:")
			.setView(renameInput)
			.setPositiveButton("Save", new DialogInterface.OnClickListener() {							
				@Override
				public void onClick(DialogInterface dialog, int which) {
					if (!TextUtils.isEmpty(renameInput.getText())){
						contactToRename.setName(renameInput.getText().toString());
						fp.update(contactToRename);
						refreshList(contactFilter.getText().toString(), sortAsc);
					}
					else{
						new AlertDialog.Builder(context)
						.setTitle("Name required")
						.setMessage("Name field must be completed.")
						.setPositiveButton("Ok", new DialogInterface.OnClickListener() {							
							@Override
							public void onClick(DialogInterface dialog, int which) {
								
							}
						}).show();			
				}						
				}
			})
			.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					// 	do nothing
 
I'm pretty sure you can't open another alert dialog without closing the first one ...

why don't you try using the .setError on your edittext ?
 
Back
Top Bottom