For e.g. an EditText it is normal to specify android:inputType="numberDecimal" for a text field supposed to contain a decimal number. But this assumes that '.' is used as the decimal separator and in some countries ',' is use开发者_开发知识库d instead. Is it possible to specify in xml that the users locale needs to be considered or do I have to do it manually in my code?
This is known bug, see here for more information.
A possible workaround is to set android:inputType="numberDecimal"
(so the digit keyboard will be opend) and android:digits="0123456789.,"
(so the comma can be entered into the EditText
). Then add a TextChangedListener
and do something like Double.parseDouble(editable.toString().replace(',', '.'));
in afterTextChanged
.
精彩评论