Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Android Number Keypad but allow negative numbers

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.

like image 875
slister Avatar asked Sep 15 '14 18:09

slister


3 Answers

android:inputType ="numbersigned"

This works for me.

like image 149
Raja Jawahar Avatar answered Oct 27 '22 06:10

Raja Jawahar


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

like image 44
ashoke Avatar answered Oct 27 '22 06:10

ashoke


Just use android:inputType="number|numberSigned" or in Java setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED)

like image 41
Carlos Coelho Avatar answered Oct 27 '22 07:10

Carlos Coelho