We need to have a numeric keyboard for an EditText
. The Keyboard should have decimal separator based on the device's selected locale. We implemented this by setting the custom DigitsKeyListener
to the EditText
public class NumericDigitsKeyListener extends DigitsKeyListener {
@Override
protected char[] getAcceptedChars() {
char[] acceptedCharacters = null;
acceptedCharacters = new char[] {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
new DecimalFormatSymbols(Locale.getDefaultLocale()).getDecimalSeparator()
return acceptedCharacters;
}
/**
* @see android.text.method.DigitsKeyListener#getInputType()
*/
public int getInputType() {
return InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL;
}
The above seems to work fine for most of the devices however for Samsung Galaxy S-II, the softkeyboard does not have comma in the keyboard.Th swype keyboard of the device displays the comma, but the default one does not.
I have tried overriding DigitsKeyListener as mentioned here
Is there a way I can enforce all the devices to have comma (when applicable or even always) to be there on numeric keyboard?