I have an EditText
field that I would like to only enter negative or positive numbers.
When I use InputType.TYPE_NUMBER
it will bring up the nice numeric keyboard which is what I want; however it will only let you enter positive numbers even though the negative button is on the numeric keyboard.
I tried using the InputType.TYPE_NUMBER_FLAG_SIGNED
and it will allow the user to enter negative or positive numbers like I want; however it brings up the standard alphabetic keyboard.
Is there anyway to bring up the numeric keyboard and allow negative numbers?
Any help with this would be greatly appreciated.
android:inputType ="numbersigned"
This works for me.
for your EditText in XML, you can force the input type to number only by using android:inputType XML attribute set to numberSigned, number or numberDecimal. You can also force it via setRawInputType.
You can also force the keypad to show only numbers by setting android:digits XML attribute
Just use android:inputType="number|numberSigned"
or in Java setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED)
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