5

I have following EditText element, when the keyboard shows up to enter value here there is a - sign shown there but nothing happens when you click it? can anyone tell me why.

<EditText
    android:id="@+id/kernelb11"
    android:layout_width="@dimen/matrixBoxWidthHeight"
    android:layout_height="@dimen/matrixBoxWidthHeight"
    android:layout_below="@+id/textViewb"
    android:layout_margin="@dimen/marginOne"
    android:background="@color/white1"
    android:gravity="center"
    android:inputType="number"
    android:maxLength="2"
    android:text="0" >
Chintan Rathod
  • 25,332
  • 13
  • 78
  • 92
Maven
  • 13,420
  • 39
  • 101
  • 157
  • 3
    possible duplicate of [Android InputType layout parameter - how to allow negative decimals?](http://stackoverflow.com/questions/5061261/android-inputtype-layout-parameter-how-to-allow-negative-decimals) – Pankaj Kumar Nov 06 '13 at 11:30

4 Answers4

8
android:inputType="numberSigned"

and it should work.

Carnal
  • 21,284
  • 6
  • 56
  • 73
5

if input type as number then - sign will not be accepted, so you need to use input type as numberSigned like

android:inputType="numberSigned"

or

android:inputType="text"
android:digits="0123456789-"

inside EditText

krishna
  • 3,996
  • 2
  • 27
  • 56
1

android:inputType="number"

A numeric only field. Corresponds to TYPE_CLASS_NUMBER | TYPE_NUMBER_VARIATION_NORMAL.

use

android:inputType="numberSigned"

Can be combined with number and its other options to allow a signed number. Corresponds to TYPE_CLASS_NUMBER | TYPE_NUMBER_FLAG_SIGNED.

Docs

Chintan Rathod
  • 25,332
  • 13
  • 78
  • 92
Tarsem Singh
  • 13,979
  • 7
  • 50
  • 70
1

If your number is to be decimal you can declare: android:inputType="numberSigned|numberDecimal"

JackAW
  • 154
  • 2
  • 14