Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

allow only number and period(.) in edit text in android

Tags:

i want to allow only numbers and period(.) in a android edit text. How to do this .. can any body help?

like image 344
Sudipta Som Avatar asked Dec 29 '10 05:12

Sudipta Som


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 I limit text editing?

This example demonstrate about How to limit text length of EditText in Android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

How do I make text not editable on android?

android:editable="false" should work, but it is deprecated, you should be using android:inputType="none" instead. Alternatively, if you want to do it in the code you could do this : EditText mEdit = (EditText) findViewById(R.


1 Answers

You should use the att:

android:digits="0123456789."

http://developer.android.com/reference/android/widget/TextView.html#attr_android:digits

like image 55
Chiara Avatar answered Nov 15 '22 12:11

Chiara