validate Required EditText - Android User Interface

Android examples for User Interface:EditText

Description

validate Required EditText

Demo Code


//package com.java2s;
import android.widget.EditText;

public class Main {
    public static boolean validateRequired(String requiredMessage,
            EditText... editTexts) {//  w w  w. j  av a 2  s  . c om
        boolean hasRequired = false;
        for (EditText editText : editTexts) {
            String textValue = editText.getText().toString();
            if (textValue.trim().isEmpty()) {
                editText.setError(requiredMessage);
                hasRequired = true;
            }
        }
        return hasRequired;
    }
}

Related Tutorials