Example usage for android.widget TextView setError

List of usage examples for android.widget TextView setError

Introduction

In this page you can find the example usage for android.widget TextView setError.

Prototype

public void setError(CharSequence error, Drawable icon) 

Source Link

Document

Sets the right-hand compound drawable of the TextView to the specified icon and sets an error message that will be displayed in a popup when the TextView has focus.

Usage

From source file:com.androidformenhancer.helper.FormHelper.java

/**
 * Sets the error icon and popup window to the specified TextView or
 * EditText.<br>//  ww w .ja v a  2 s  .c o  m
 * Before calling this, you must call {@linkplain #validate()} or
 * {@linkplain #validateText(int)} to get validation result.
 *
 * @param result   validation result
 * @param textView TextView or EditText object which you want to set error
 */
public void setErrorToTextView(final ValidationResult result, final TextView textView) {
    if (mValidationErrorIconEnabled) {
        int id = textView.getId();
        if (result.hasErrorFor(id)) {
            textView.setError(StringUtils.serialize(result.getErrorsFor(id)), mIconError);
            textView.setCompoundDrawables(null, null, mIconError, null);
        } else {
            textView.setCompoundDrawables(null, null, mIconOk, null);
        }
    }
}