Back to project page wiki-contacts-android.
The source code is released under:
Apache License
If you think the Android project wiki-contacts-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.kahkong.wikicontacts.form; /*from w w w.ja va2 s .co m*/ import com.kahkong.wikicontacts.callback.Validator; import android.content.Context; import android.text.Editable; import android.text.TextWatcher; import android.util.AttributeSet; import android.widget.EditText; /** * * @author Poh Kah Kong * */ public class EditTextForm extends EditText { private Validator validator; private String[] errorMsgs; private boolean isSubmitted = false; public EditTextForm(Context context) { super(context); } public EditTextForm(Context context, AttributeSet attrs) { super(context, attrs); } public String getValue() { String value = getText().toString(); return !value.equals("") ? value:null; } public void setValue(String value) { if (value==null) { return; } setText(value); } public void setValidator(final Validator validator, String[] errorMsgs) { this.validator = validator; this.errorMsgs = errorMsgs; addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable editable) { if (!isSubmitted) { return; } isValidated(); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); } public boolean submit() { isSubmitted = true; return isValidated(); } private boolean isValidated() { if (validator==null) { return true; } int status = validator.validate(getText().toString()); if (status>0) { setError(errorMsgs[status-1]); return false; } else { return true; } } }