EditText
中的inputType
numberDecimal
使用点.
作为小数分隔符.在欧洲,用逗号,
代替是很常见的.即使我的区域设置为德语,小数分隔符仍然是.
有没有办法把逗号作为小数点分隔符?
EditText
中的inputType
numberDecimal
使用点.
作为小数分隔符.在欧洲,用逗号,
代替是很常见的.即使我的区域设置为德语,小数分隔符仍然是.
有没有办法把逗号作为小数点分隔符?
一个变通办法(在谷歌修复这个错误之前)是使用带有android:inputType="numberDecimal"
和android:digits="0123456789.,"
的EditText
.
然后在EditText中添加一个TextChangedListener,其后文本更改如下:
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
}