我有一个edittext
,它只能输入整数而不能输入带小数点的数字。
android:inputType="number"
我希望在打字时将数字千位分隔。例如:25,000。
我知道应该使用 TextWatcher
并且我已经使用了以下代码,但无法使其正常工作:
@Override
public void afterTextChanged(Editable viewss) {
String s = null;
try {
// The comma in the format specifier does the trick
s = String.format("%,d", Long.parseLong(viewss.toString()));
} catch (NumberFormatException e) {
}
}
你能帮我做这件事吗?