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,864
  • 13
  • 83
  • 93
Maven
  • 14,587
  • 42
  • 113
  • 174
  • 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

10
android:inputType="numberSigned"

and it should work.

Carnal
  • 21,744
  • 6
  • 60
  • 75
6

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
  • 4,069
  • 2
  • 29
  • 56
2

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

JackAW
  • 164
  • 2
  • 14
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,864
  • 13
  • 83
  • 93
Tarsem Singh
  • 14,139
  • 7
  • 51
  • 71