How can I enter only alphabets in EditText in android?
You can use android:inputType="number" in the XML file. You can specify other values such as numberDecimal as well. Also, you might additionally want to use android:singleLine="true" for a single line Edittext .
The most reliable way to do this is using UI. setReadOnly(myEditText, true) from this library. There are a few properties that have to be set, which you can check out in the source code.
If you want your disabled EditText to look the same as your enabled one, you should use android:enabled="false" in combination with android:textColor="..." . Show activity on this post. Used this if you have an icon to be clickable, this works for me.
In android, we can set the text of EditText control either while declaring it in Layout file or by using setText() method in Activity file.
Add this line with your EditText tag.
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
Your EditText tag should look like:
<EditText android:id="@+id/editText1" android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" android:layout_width="fill_parent" android:layout_height="wrap_content" />
edittext.setFilters(new InputFilter[] { new InputFilter() { public CharSequence filter(CharSequence src, int start, int end, Spanned dst, int dstart, int dend) { if(src.equals("")){ // for backspace return src; } if(src.toString().matches("[a-zA-Z ]+")){ return src; } return edittext.getText().toString(); } } });
please test thoroughly though !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With