Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make edittext field for decimals

Tags:

android

how to make dynamically edittext field for accepting only double and float values?

like image 517
Aswan Avatar asked Nov 25 '10 10:11

Aswan


2 Answers

Use this method in your Activity:

EditText et = (EditText) findViewById(R.id.text01);
et.setInputType(0x00002002);

or

EditText et = (EditText) findViewById(R.id.text01) ;
et.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);

here text01 is id of EditText field in your R.java file;

Reference:

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

like image 131
Vikas Patidar Avatar answered Oct 13 '22 00:10

Vikas Patidar


Maybe a nicer solution would be using

    et.setInputType(InputType.TYPE_CLASS_NUMBER 
                         | InputType.TYPE_NUMBER_FLAG_DECIMAL);

Edit: I have also added the flag InputType.TYPE_NUMBER_FLAG_DECIMAL to accept dobules too.

like image 22
Ovidiu Latcu Avatar answered Oct 13 '22 01:10

Ovidiu Latcu