10

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.

A P
  • 2,131
  • 2
  • 24
  • 36
slister
  • 769
  • 1
  • 13
  • 29

4 Answers4

7
android:inputType ="numbersigned"

This works for me.

Raja Jawahar
  • 6,742
  • 9
  • 45
  • 56
3

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

ashoke
  • 6,441
  • 2
  • 26
  • 25
1

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

Carlos Coelho
  • 31
  • 2
  • 5
0
fromEditText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL
                    | InputType.TYPE_NUMBER_FLAG_SIGNED);

Now this allows you to set Negative/Decimal/Standard numbers

A P
  • 2,131
  • 2
  • 24
  • 36