Кнопка точка или запятая отключена, если нажата кнопка inputType = "number" или inputType = "number | Decimal". Он не работал с андроид: цифры = ".", также.Невозможно добавить десятичное значение с помощью EditText inputType = "number" Android
Редактирование содержит текстовый элемент, который форматирует число. Текст выглядит следующим образом:
mEditWithdrawalAmount.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
@Override
public void afterTextChanged(Editable s) {
if (!s.toString().equals(current)) {
mEditWithdrawalAmount.removeTextChangedListener(this);
String replaceable = String.format("[%s .\\s]", NumberFormat.getCurrencyInstance().getCurrency().getSymbol());
String cleanString = s.toString().replaceAll(replaceable, "").replace("R","").replace(",","");
double parsed;
try {
parsed = Double.parseDouble(cleanString);
} catch (NumberFormatException e) {
parsed = 0.00;
}
String formatted = Utils.formatCurrency(parsed);
current = formatted;
mEditWithdrawalAmount.setText(formatted);
mEditWithdrawalAmount.setSelection(formatted.length());
// Do whatever you want with position
mEditWithdrawalAmount.addTextChangedListener(this);
}
}
});
Проблема заключается в том, что edittext также должен содержать числа с десятичной точкой.
- Фактический результат: R1000 000
- Желаемый результат R1000 000,00 или R1000 000,40
В вашем XML editext андроида: inputType = "numberDecimal" –
андроид: inputType = "numberDecimal" работает только без onTextChange Слушатель – BigWiz