Text Only Input EditText android
I want to restric user from entering any special character or number into edit text, but programmatically it should allow.
I know I can make inputType="text"
but it deals only with the softkeyboard. I think it can be achive开发者_如何学God with TextWatcher, but I am not able to gel evrything. Can anyone help ?
editTextView.setInputType(InputType.TYPE_TEXT_VARIATION_NORMAL);
There are many other types of inputs available for Password, Email address etc. Please see This API Link
Thanks :)
You can filter input text by following ,
etTwamboxName.setFilters(new InputFilter[] { new InputFilter() {
public CharSequence filter(CharSequence src, int start, int end,
Spanned dst, int dstart, int dend) {
Log.e("", "===> " + src);
if (src.equals("")) { // for backspace
return src;
}
if (src.toString().matches("[a-zA-Z ]+.")) {
return src;
}
return "";
}
} });
Try this way,Reference
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
android:inputType="text"
For more info, you may check http://developer.android.com/reference/android/widget/TextView.html#attr_android:digits
精彩评论