I’m a bit struggling with some editText :S I’d like to check with some conditions if the user has filled a field or not : my code just doesn’t seem to work.
The code :
…
input.setText("rrr");
input2.setText("rrr");
AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
builder.setCancelable(true);
builder.setTitle("Add a friend");
builder.setMessage("Fill in the fields you know :");
builder.setView(layout);
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if(input.getEditableText() != null && input2.getEditableText() != null && input3.getEditableText() != null){
Dialog d = new Dialog(ctx);
d.setTitle("BLiBLiBLi !");
d.show();
}else if(input.getEditableText() != null && input2.getEditableText() != null && input3.getEditableText() == null){
Dialog d = new Dialog(ctx);
d.setTitle("BLABLABLA !");
d.show();
}
…
as you can see, the first 2 fields are have a setText(“rrr”); but not the third one…
So the second condition should point out (if I don’t fill in the third input) and I should get the BLABLABLA message but I m always getting the BLiBLiBLi :'( (it’s only a test of course :p)
I’ve already tried to change input.getEditableText() != null with input.getEditableText().toString != “” or setting the inputs like this input.setText(“”); or input.setText(null); : it just doesn’t work I always end up in the first condition that thinks all my fields have been filled in with something
Just check the length of text in each
EditText. This will do what you want…