经过多次尝试,我设法为 Float 创建了一个模式,我设法通过返回 ActivityResult 并将其设置在相应的字段中来完成。现在我的这个 TextWatcher 有问题,它不接受 Float 的模式,有人能帮我吗?
这是 TextWather
private abstract class TextChangedListener implements TextWatcher
{
public abstract void numberEntered(Float number);
@Override
public void afterTextChanged(Editable s)
{
String text = s.toString();
try
{
Float parsedFloat = Float.valueOf(text);
numberEntered(parsedFloat);
} catch (NumberFormatException e)
{
Log.w(getPackageName(), "Non si puo' parsare '" + text + "' col numero", e);
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after)
{
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count)
{
}
}
这是 float 模式
DecimalFormat dec = new DecimalFormat("###,##0.00", DecimalFormatSymbols.getInstance(Locale.ITALIAN));
最佳答案
感谢大家!我用这个方法解决了我的问题!
private void decimalFormatWithSymbol() {
dec = new DecimalFormat("##0.00", DecimalFormatSymbols.getInstance(Locale.ITALIAN));
dfs = new DecimalFormatSymbols();
dfs.setDecimalSeparator('.');
dec.setDecimalFormatSymbols(dfs);
}
关于android - DecimalFormat float 上的 NumberFormatException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29185254/