how to make dynamically edittext field for accepting only double and float values?
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
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.
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