Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create EditText accepts Alphabets only in android?

How can I enter only alphabets in EditText in android?

like image 749
UMAR-MOBITSOLUTIONS Avatar asked Mar 02 '10 07:03

UMAR-MOBITSOLUTIONS


People also ask

How can add only numbers 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 .

How do you make EditText read only?

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.

How do I edit EditText Uneditable?

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.

Can you set text in EditText?

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.


2 Answers

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" /> 
like image 119
Sandeep Avatar answered Sep 20 '22 09:09

Sandeep


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 !

like image 20
Subhas Avatar answered Sep 23 '22 09:09

Subhas