user3144239
user3144239

Reputation: 27

Only allow numbers in an EditText

How do I allow only numbers in an EditText. I don't want to allow decimals or letters, but only numeric values.

Upvotes: 2

Views: 984

Answers (4)

Android Killer
Android Killer

Reputation: 18509

android:inputType="number" in your edittext in xml file.

Upvotes: 3

S.Thiongane
S.Thiongane

Reputation: 6915

JAVA : edittext.setRawInputType(InputType.TYPE_CLASS_NUMBER);

in XML:

<EditText   
    // ...
    android:inputType="number" 
    // ...  />

Upvotes: 1

Orphamiel
Orphamiel

Reputation: 884

In addition to the above comments, this will also work(However, it does not make the keyboard switch to number mode) :

android:digits="0123456789"

Upvotes: 2

Gokul Nath KP
Gokul Nath KP

Reputation: 15574

Set inputType="number" in EditText.

Upvotes: 4

Related Questions