我使用MVP来验证用户输入,我发送编辑文本的标签以基于标签进行验证,因此,如果我的名字有正则表达式,等等。 基于验证,我启用或禁用注册按钮 一切正常,但android 8自动填充API出现问题,如果表单具有名字和姓氏,它将在这里填充所有问题,当我获得当前焦点编辑文本时,它将仅获取第一个,所以当自动填充API设置姓氏当前焦点editext是姓氏 活动中的代码
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void afterTextChanged(Editable editable) {
View focView=getActivity().getCurrentFocus();
/* if t use EditText.settxt to change text and the user has no
* CurrentFocus the focView will be null
*/
if(focView!=null)
{
getPresenter().validateInput((focView.getTag(), editable.toString());
}
}
演示者中的代码
@Override
public void validateInput(Object tag, String s) {
if (tag == null)
return;
switch ((InputsFieldsEnum) tag) {
case FIRST_NAME:
user.setFirstName(s);
validateFirstName(s);
break;
case LAST_NAME:
user.setLastName(s);
validateLastName(s);
break;
case PHONE_NUMBER:
user.setPhoneNumberWithoutCode(s);
user.setCountryCodeIso(getView().getSelectedCountry().getDialCode());
validatePhoneNumber(getView().getSelectedCountry().getDialCode(), s);
break;
}
validateUserInputs();
}
因此,有什么方法可以在TextWatcher上获取编辑文本,而无需在视图中(激活)编写更多逻辑