I am trying to validate some EditText with a TextWathcher as follows:
TextWatcher textWatcher = new TextWatcher() {
boolean ServerOK = false;
boolean NameOK = false;
boolean EmpidOK = false;
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
String txtName = txtEmployeeName.getText().toString();
String txtEmpid = txtEmployeeID.getText().toString();
if(URLUtil.isValidUrl(txtServerName.getText().toString()))
{
ServerOK = true;
}
// Name input is fine
if(txtName.length() > -1) {
NameOK = true;
}
// Employee ID input is fine
if(txtEmpid.length() > -1) {
EmpidOK = true;
}
// Validate both fields and activate button if all OK
if (NameOK && ServerOK && EmpidOK) {
btnRegister.setEnabled(true);
} else {
btnRegister.setEnabled(false);
}
System.out.println(NameOK + " " + EmpidOK + " " + ServerOK);
}
};
txtEmployeeName.addTextChangedListener(textWatcher);
txtServerName.addTextChangedListener(textWatcher);
txtEmployeeID.addTextChangedListener(textWatcher);
}
The issue is that when typing in some text in the EdiText the booleans are set correctly. If I delete any of the strings in the TexViews as soon as I hit 0 characters in the EditText:
E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
What could be the cause of this error?