android.support.design.widget.TextInputLayout#setError ( )源码实例Demo

下面列出了android.support.design.widget.TextInputLayout#setError ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

private void showErrorMessage(View view, int errorMessageId){
    // reset error messages
    ((TextInputLayout)referenceActivity.findViewById(R.id.inputFoodName)).setError("");
    ((TextInputLayout)referenceActivity.findViewById(R.id.inputCalories)).setError("");
    ((TextInputLayout)referenceActivity.findViewById(R.id.inputFoodAmount)).setError("");

    // if the view that this is called on is a TextInputlayout, we can show the error on the TextinputLayout
    if(view instanceof TextInputLayout){
        TextInputLayout til = (TextInputLayout) view;
        til.setError(getString(errorMessageId));
    } else {
        //otherwise show a generic error message
        Snackbar.make(view, errorMessageId, Snackbar.LENGTH_LONG)
                .setAction("Action", null).show();
    }
}
 
源代码2 项目: q-municate-android   文件: ValidationUtils.java
public boolean isFullNameValid(TextInputLayout fullNameTextInputLayout, String newFullName) {
    boolean fullNameEntered = !TextUtils.isEmpty(newFullName.trim());
    boolean valid = true;

    if (fullNameEntered) {
        if (newFullName.length() < FULL_NAME_MIN_LENGTH) {
            valid = false;
            fullNameTextInputLayout.setError(context.getString(R.string.auth_full_name_field_is_too_short));
        } else if (newFullName.length() > FULL_NAME_MAX_LENGTH) {
            valid = false;
            fullNameTextInputLayout.setError(context.getString(R.string.auth_full_name_field_is_too_long));
        }
    } else {
        valid = false;
        fullNameTextInputLayout.setError(context.getString(R.string.profile_full_name_not_entered));
    }

    return valid;
}
 
源代码3 项目: OmniList   文件: FeedbackDialog.java
@Override
public void afterTextChanged(Editable s) {
    TextInputLayout et = weakEt.get();
    if (StringUtils.validate(s.toString())) {
        if (et != null) et.setErrorEnabled(false);
        return;
    }
    if (et != null) {
        et.setErrorEnabled(true);
        et.setError(PalmApp.getContext().getString(R.string.illegal_email_format));
    }
}
 
源代码4 项目: GittyReporter   文件: GittyReporter.java
private void setError(TextView view, String text) {
    TextInputLayout parent = (TextInputLayout) view.getParent();

    // there is a small flashing when the error is set again
    // the only way to fix that is to track if the error is
    // currently shown, because for some reason TextInputLayout
    // doesn't provide any getError methods.
    parent.setError(text);
}
 
@Override
public void execute(ValidationHolder validationHolder, Matcher matcher) {
    TextInputLayout textInputLayout = validationHolder.getTextInputLayout();
    textInputLayout.setErrorTextAppearance(mErrorTextAppearance);
    textInputLayout.setErrorEnabled(true);
    textInputLayout.setError(validationHolder.getErrMsg());
}
 
@Override
public void halt() {
    for (ValidationHolder validationHolder : mValidationHolderList) {
        if (validationHolder.isSomeSortOfView()) {
            validationHolder.resetCustomError();
        } else {
            TextInputLayout textInputLayout = validationHolder.getTextInputLayout();
            textInputLayout.setErrorEnabled(false);
            textInputLayout.setError(null);
        }
    }
}
 
private boolean validateInput(EditText EdTxt, TextInputLayout inputLayout) {
    if (EdTxt.getText().toString().trim().isEmpty()) {
        inputLayout.setError(getString(R.string.err_msg_input));
        requestFocus(EdTxt);
        return false;
    } else {
        inputLayout.setErrorEnabled(false);
    }

    return true;
}
 
源代码8 项目: q-municate-android   文件: ValidationUtils.java
public boolean isLoginDataValid(TextInputLayout emailTextInputLayout,
                                TextInputLayout passwordTextInputLayout, String email, String password) {
    boolean isEmailEntered = !TextUtils.isEmpty(email.trim());
    boolean isPasswordEntered = !TextUtils.isEmpty(password.trim());

    if (isEmailEntered && isPasswordEntered) {
        boolean valid = true;
        if (!isEmailValid(email)) {
            valid = false;
            emailTextInputLayout.setError(context.getString(R.string.auth_email_field_is_incorrect));
        }
        if (password.length() < PASSWORD_MIN_LENGTH) {
            valid = false;
            passwordTextInputLayout.setError(context.getString(R.string.auth_password_field_is_too_short));
        }
        return valid;
    } else if (!isEmailEntered && !isPasswordEntered) {
        emailTextInputLayout.setError(context.getString(R.string.auth_not_all_fields_entered));
        passwordTextInputLayout.setError(context.getString(R.string.auth_not_all_fields_entered));
    } else {
        if (!isEmailEntered) {
            emailTextInputLayout.setError(context.getString(R.string.auth_email_field_not_entered));
        }
        if (!isPasswordEntered) {
            passwordTextInputLayout.setError(context.getString(R.string.auth_password_field_not_entered));
        }
    }

    return false;
}
 
源代码9 项目: q-municate-android   文件: ValidationUtils.java
public boolean isChangePasswordDataValid(TextInputLayout oldPasswordTextInputLayout,
                                         TextInputLayout newPasswordTextInputLayout, String oldPassword, String newPassword) {
    boolean isOldPasswordEntered = !TextUtils.isEmpty(oldPassword.trim());
    boolean isNewPasswordEntered = !TextUtils.isEmpty(newPassword.trim());

    if (isOldPasswordEntered && isNewPasswordEntered) {
        if (!qbUser.getPassword().equals(oldPassword)) {
            oldPasswordTextInputLayout.setError(context.getString(R.string.change_password_old_password_wrong));
        } else {
            return true;
        }
    } else if (!isOldPasswordEntered && !isNewPasswordEntered) {
        oldPasswordTextInputLayout.setError(context.getString(R.string.change_password_all_fields_not_entered));
        newPasswordTextInputLayout.setError(context.getString(R.string.change_password_all_fields_not_entered));
    } else {
        if (!isOldPasswordEntered) {
            oldPasswordTextInputLayout
                    .setError(context.getString(R.string.change_password_old_password_not_entered));
        }
        if (!isNewPasswordEntered) {
            newPasswordTextInputLayout
                    .setError(context.getString(R.string.change_password_new_password_not_entered));
        }
    }

    return false;
}
 
源代码10 项目: mv2m   文件: DataBindingConverters.java
@BindingAdapter({"app:error"})
public static void bindValidationError(TextInputLayout textInputLayout, int errorRes) {
    if (errorRes != 0) {
        textInputLayout.setError(textInputLayout.getResources().getString(errorRes));
    } else {
        textInputLayout.setError(null);
    }
}
 
源代码11 项目: AndroidSDK   文件: AddDataStreamActivity.java
private boolean checkInput(TextInputLayout textInputLayout, int errorResId) {
    String text = textInputLayout.getEditText().getText().toString();
    if (TextUtils.isEmpty(text)) {
        textInputLayout.setError(getResources().getString(errorResId));
        textInputLayout.requestFocus();
        return false;
    }
    return true;
}
 
源代码12 项目: AndroidSDK   文件: AddDeviceActivity.java
private boolean checkInput(TextInputLayout textInputLayout, int errorResId) {
    String text = textInputLayout.getEditText().getText().toString();
    if (TextUtils.isEmpty(text)) {
        textInputLayout.setError(getResources().getString(errorResId));
        textInputLayout.requestFocus();
        return false;
    }
    return true;
}
 
源代码13 项目: AndroidSDK   文件: EditDeviceActivity.java
private boolean checkInput(TextInputLayout textInputLayout, int errorResId) {
    String text = textInputLayout.getEditText().getText().toString();
    if (TextUtils.isEmpty(text)) {
        textInputLayout.setError(getResources().getString(errorResId));
        textInputLayout.requestFocus();
        return false;
    }
    return true;
}
 
源代码14 项目: q-municate-android   文件: ValidationUtils.java
public boolean isForgotPasswordDataValid(TextInputLayout emailTextInputLayout, String email) {
    boolean isEmailEntered = !TextUtils.isEmpty(email.trim());

    if (isEmailEntered) {
        if (!isEmailValid(email)) {
            emailTextInputLayout.setError(context.getString(R.string.forgot_password_email_field_is_incorrect));
        } else {
            return true;
        }
    } else {
        emailTextInputLayout.setError(context.getString(R.string.forgot_password_email_field_not_entered));
    }

    return false;
}
 
源代码15 项目: Orin   文件: BugReportActivity.java
private void setError(TextInputEditText editText, @StringRes int errorRes) {
    TextInputLayout layout = (TextInputLayout) editText.getParent();
    layout.setError(getString(errorRes));
}
 
源代码16 项目: Orin   文件: BugReportActivity.java
private void removeError(TextInputEditText editText) {
    TextInputLayout layout = (TextInputLayout) editText.getParent();
    layout.setError(null);
}
 
源代码17 项目: OpenYOLO-Android   文件: DataBindingAdapters.java
/**
 * Facilitates binding error text to a TextInputLayout.
 */
@BindingAdapter("errorText")
public static void setErrorText(TextInputLayout layout, String errorText) {
    layout.setError(errorText);
}
 
源代码18 项目: meiShi   文件: LoginActivity.java
private void setEditTextError(TextInputLayout layout, int msgId) {
    layout.setErrorEnabled(true);
    layout.setError(getString(msgId));
}
 
源代码19 项目: GankGirl   文件: SubmitGankActivity.java
private void setError(TextInputEditText editText, @StringRes int errorRes) {
    TextInputLayout layout = (TextInputLayout) editText.getParent().getParent();
    layout.setError(getString(errorRes));
}
 
源代码20 项目: meiShi   文件: SignUpActivity.java
private void setEditTextError(TextInputLayout layout, int msgId) {
    layout.setErrorEnabled(true);
    layout.setError(getString(msgId));
}