Notbad
Notbad

Reputation: 6296

Soft keyboard with comma instead of dot for decimal separator in android

I have been reading some threads about this problem and some are not answered and others (from 2011) explain how this was a known bug.

Has this been solved? Is it possible right now to show soft keyboard with culture information? I would like to show a decimal keyboard showing a "," instead of a "dot" for the decimal separator.

Upvotes: 3

Views: 14519

Answers (4)

Jorge Alcolea Coronel
Jorge Alcolea Coronel

Reputation: 43

It is not possible to not show the '.' in the soft keyboard without creating your own one. The solution than I found is:

<EditText
    android:inputType="numberDecimal"
    android:digits="0123456789," />

This way when you press the '.' in the soft keyboard nothing happens; only numbers and comma are allowed

Upvotes: 4

android
android

Reputation: 43

In android namespace you can use:

android:inputType="numberDecimal"

Which enables you to input the "."

Upvotes: -4

MiaN KhaLiD
MiaN KhaLiD

Reputation: 1518

You can use the following workaround to also include comma as a valid input:-

Through XML:

<EditText
    android:inputType="number"
    android:digits="0123456789.," />

Programmatically:

EditText input = new EditText(THE_CONTEXT);
input.setKeyListener(DigitsKeyListener.getInstance("0123456789.,"));

In this way Android system will show the numbers' keyboard and allow the input of comma. Hope it helps :)

Upvotes: 18

Bondax
Bondax

Reputation: 3163

I solved this by extending NumberKeyListener to accept ',' and '.', and overrode:

@Override
public int getInputType() {
   return InputType.TYPE_CLASS_NUMBER 
          | InputType.TYPE_NUMBER_FLAG_DECIMAL 
          | InputType.TYPE_NUMBER_FLAG_SIGNED;
}

Furthermore I set a TextWatcher on the EditText, which replaced all '.' with ',' in afterTextChanged().

But I could not manage to show a comma on the softkeyboard.

Upvotes: 2

Related Questions