Android键盘没有解雇

时间:2012-01-13 07:44:02

标签: java android

在我的Android应用程序中,键盘表现得很奇怪。一切正常,直到按下退格键。 当按下退格键时,编辑文本将不会读取输入的下一个字符。(假设编辑文本显示123.我按了退格键。现在显示12.现在我决定输入5,点击5编辑文本仍显示12.再次输入5。它有效。)

我正在为此editText使用textchange侦听器。在onTextChanged方法中,以下代码用于格式化输入的数字。 (当输入1时,它将呈现为00.01。如果在此之后输入2,它将呈现为00.12)。

if (!s.toString().equals(_currentFare)) {


    _fareText.removeTextChangedListener(this);

    String cleanString = s.toString().replace(".", "");

    double parsed = Double.parseDouble(cleanString);

    DecimalFormat decimalFormat = new DecimalFormat(
            IGConstants.zeroBalance);
    String formated = (String.valueOf(decimalFormat
            .format(parsed / 100)));

    // The formatted text will contain a ','. For converting
    // this to double for calculation
    // purpose the comma is removed
    _currentFare = formated.replace(",", "");
    if (_currentFare.equals("") || _currentFare.equals("0")) {
        _currentFare = IGConstants.zeroBalance;
    }
    _fareText.setText(_currentFare);
    _fareText.setSelection(_currentFare.length());

    _fareText.addTextChangedListener(this);

}

当我删除上面的代码片段时,它运行正常。但是我需要这个来格式化输入的文本。

0 个答案:

没有答案
相关问题