Android Open Source - ExpertAndroid Field

From Project

Back to project page ExpertAndroid.


The source code is released under:

MIT License

If you think the Android project ExpertAndroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.iuriio.demos.expertandroid.ch6forms;
//  w  w w  . j a  va2 s  . c o  m
import android.widget.TextView;

import java.util.ArrayList;

 * Created by iuriio on 10/24/13.
public class Field implements IValidator {
    private TextView control;
    private boolean required = true;
    private ArrayList<IValueValidator> valueValidatorList = new ArrayList<IValueValidator>();

    public Field(TextView tv) {
        this(tv, true);

    public Field(TextView tv, boolean required) {
        this.control = tv;
        this.required = required;

    public void addValidator(IValueValidator validator) {

    public boolean validate() {
        String value = this.getValue();
        if (StringUtils.invalidString(value)) {
            if (this.required) {
                return false;

        for (IValueValidator validator : this.valueValidatorList) {
            boolean result = validator.validateValue(this.getValue());
            if (result) {

            String errorMessage = validator.getErrorMessage();
            return false;

        return true;

    private void warnRequiredField() {
        this.setErrorMessage("This is a required field");

    public void setErrorMessage(String message) {

    public String getValue() {
        return this.control.getText().toString();

Java Source Code List