is EditText Empty Error - Android User Interface

Android examples for User Interface:EditText

Description

is EditText Empty Error

Demo Code


//package com.java2s;
import android.content.Context;
import android.support.annotation.StringRes;
import android.text.TextUtils;

import android.widget.EditText;

public class Main {

    public static boolean isEditTextEmptyError(Context context,
            EditText editText, CharSequence sequence,
            @StringRes int errorRes) {
        if (editText == null) {
            throw new NullPointerException("editText is Null");
        }//  ww w  . ja v  a 2 s.  c  om
        if (TextUtils.isEmpty(sequence)) {
            editText.setError(context.getString(errorRes));
            return true;
        }
        editText.setError(null);
        return false;
    }
}

Related Tutorials