Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL) brings normal (letters) keyboard

I am setting (programmatically) the input type of several EditText that way, so keyboard with only numbers pops up to the user. But it is not working, the normal keyboard, with letters, appears. If I set them to setInputType(InputType.TYPE_CLASS_NUMBER) appears the keyboard I want, but I am not able to set a decimal value. Dot simply doesn't appear. I tried with setRawInputType, but it does not work neither. i was not able to find a question here in SO regarding that issue.

Is that a bug, or something I am not doing well? How could I show the numeric keyboard, and be able to assign a decimal value?

As a side note, i am using an Experia M2 to try.

Thank you.

like image 258
Fustigador Avatar asked Dec 24 '22 23:12

Fustigador


1 Answers

Found the solution, you need to set BOTH types:

Java:

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

Kotlin:

editText.inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL
like image 73
Fustigador Avatar answered Dec 26 '22 16:12

Fustigador