相关疑难解决方法(0)

在Android中使用千位分隔符(,)键入时如何格式化EditText的输入?

我有一个edittext,它只获得没有十进制数字的数字.

android:inputType="number"
Run Code Online (Sandbox Code Playgroud)

我打算在打字的时候把数千人分开.例如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) {
            }

        }
Run Code Online (Sandbox Code Playgroud)

你能帮我这么做吗?

java android number-formatting textwatcher android-edittext

9
推荐指数
2
解决办法
9617
查看次数