EditText
中的inputType
numberDecimal
使用点.
作为小数分隔符。在欧洲,通常使用逗号 ,
代替。即使我的语言环境设置为德语,小数点分隔符仍然是 .
有没有办法将逗号作为小数分隔符?
最佳答案
一种解决方法(直到 Google 修复此错误)是使用带有 android:inputType="numberDecimal"
和 android:digits="0123456789 的
。 EditText
。 ,”
然后使用以下 afterTextChanged 将 TextChangedListener 添加到 EditText:
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
}
关于android - 小数分隔符逗号 (',' )在 EditText 中带有 numberDecimal inputType,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3821539/