Example usage for android.widget TextView getError

List of usage examples for android.widget TextView getError

Introduction

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

Prototype

public CharSequence getError() 

Source Link

Document

Returns the error message that was set to be displayed with #setError , or null if no error was set or if it the error was cleared by the widget after user input.

Usage

From source file:Main.java

/**
 * Checks if a View matches a certain string and returns the amount of total matches.
 * // w ww .j a v  a  2  s. c om
 * @param regex the regex to match
 * @param view the view to check
 * @param uniqueTextViews set of views that have matched
 * @return number of total matches
 */

public static int getNumberOfMatches(String regex, TextView view, Set<TextView> uniqueTextViews) {
    if (view == null) {
        return uniqueTextViews.size();
    }

    Pattern pattern = null;
    try {
        pattern = Pattern.compile(regex);
    } catch (PatternSyntaxException e) {
        pattern = Pattern.compile(regex, Pattern.LITERAL);
    }

    Matcher matcher = pattern.matcher(view.getText().toString());

    if (matcher.find()) {
        uniqueTextViews.add(view);
    }

    if (view.getError() != null) {
        matcher = pattern.matcher(view.getError().toString());
        if (matcher.find()) {
            uniqueTextViews.add(view);
        }
    }
    if (view.getText().toString().equals("") && view.getHint() != null) {
        matcher = pattern.matcher(view.getHint().toString());
        if (matcher.find()) {
            uniqueTextViews.add(view);
        }
    }
    return uniqueTextViews.size();
}