Decimal separator comma (',') with numberDecimal inputType in EditText
A workaround (until Google fix this bug) is to use an EditText
with android:inputType="numberDecimal"
and android:digits="0123456789.,"
.
Then add a TextChangedListener to the EditText with the following afterTextChanged:
public void afterTextChanged(Editable s) {
double doubleValue = 0;
if (s != null) {
try {
doubleValue = Double.parseDouble(s.toString().replace(',', '.'));
} catch (NumberFormatException e) {
//Error
}
}
//Do something with doubleValue
}
A variation on the 'digit' solutions offered here:
char separator = DecimalFormatSymbols.getInstance().getDecimalSeparator();
input.setKeyListener(DigitsKeyListener.getInstance("0123456789" + separator));
Taking into account the locale separator.