androidandroid-inputtypeandroid-textinputedittext

How to set an InputType to display negative float number for an inputTypeEditText


I need to display negative and positive values inside an TextInputEditText. I am setting the inputType programatically:

inputTypeEditText.setInputType(InputType.TYPE_CLASS_NUMBER | 
InputType.TYPE_NUMBER_FLAG_DECIMAL);

the above code works for positive float numbers only.

And also I tried

inputTypeEditText.setInputType(InputType.TYPE_CLASS_NUMBER | 
InputType.TYPE_NUMBER_FLAG_SIGNED);

but this keyboard is similar with the text keyboard and shows to much characters.


Solution

  • I made the float keyboard which displays float positive and negative numbers using the following code:

    inputTypeEditText.setInputType(InputType.TYPE_NUMBER_FLAG_SIGNED|
               InputType.TYPE_CLASS_NUMBER|InputType.TYPE_NUMBER_FLAG_DECIMAL);