我有一个 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) {
}
}
你能帮我这样做吗?
最佳答案
将其添加到您应用的 Gradle 中 编译 'com.aldoapps:autoformatedittext:0.9.3' 在 XML 中 xmlns:app="http://schemas.android.com/apk/res-auto"
<com.aldoapps.autoformatedittext.AutoFormatEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:isDecimal="true"
android:maxLength="8"
android:id="@+id/number"/>
本库自动添加(,)(.)
关于java - 在Android中使用千位分隔符(,)输入时如何格式化EditText的输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28757931/