I have found answers to limit it to Integer/float in xml, I want to do it programmatically.
I can set setInputType(InputType.TYPE_CLASS_NUMBER)
for integer values, but what for float values?
I want them in xxxx.xxx
format.
I think you are looking for
android:inputType="numberDecimal"
in the xml file and
InputType.TYPE_NUMBER_FLAG_DECIMAL
in the java source file.
TYPE_NUMBER_FLAG_DECIMAL is a flag of TYPE_CLASS_NUMBER and allows decimal inputs.
For more information see this
In another way you can test the input value using
if(editText.getText().toString().contains("."))
//Its a float value
else
//Not a float value
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