这里的目标是在用户输入联系信息时验证每个字段,并最终对每个字段应用自动格式(大写、拼写等)。
我几乎可以使用以下代码进行此操作,但它基于按键回调,而我真正想要触发的是每个文本字段的“失去焦点”。有任何想法吗?
public TextFormValidationCallback (CustomerFormActivity faja, String editTextName, Context context, EditText textField,
Button button, int rule) {
this.button = button;
this.textField = textField;
this.context = context;
this.ruleResourceId = rule;
this.editTextName = editTextName;
this.faja = faja;
this.res = context.getResources();
}
public boolean onEditorAction(TextView v, int keyCode, KeyEvent event) {
if (event != null) {
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN)
&& (keyCode == KeyEvent.KEYCODE_ENTER)) {
// Perform action on key press
Log.i("TextFormValidation",
"TextFormValidation callback activated!");
if (validateTextFieldNotNullData(this.textField)
&& (validateTextFieldFormat(this.textField,
ruleResourceId))) {
faja.setFieldValidationArray(getHeadingIndex(editTextName),
true);
if (faja.sumFieldValidations()) {
button.setClickable(true);
button.setText(R.string.addCustomer);
}
} else {
button.setText(R.string.next);
button.setClickable(false);
}
return true;
}
} else {
}
return false;
}