Android 在TextWatcher中更改后文本中的setText使保留退格无效

Android 在TextWatcher中更改后文本中的setText使保留退格无效,android,Android,我正在使用addTextChangedListener(myTextWatcher)到我的editText中,以获得某种货币格式。 在我的TextWatcher中的extchanged中有setText() public void afterTextChanged(Editable s) { et.removeTextChangedListener(this); (snipped) et.setText(someText);

我正在使用
addTextChangedListener(myTextWatcher)
到我的
editText
中,以获得某种货币格式。 在我的
TextWatcher
中的
extchanged
中有
setText()

  public void afterTextChanged(Editable s) {
        et.removeTextChangedListener(this);

        (snipped)
        et.setText(someText);
        (snipped)

        et.addTextChangedListener(this);
    }
问题是,即使按住backspace键,我也只能删除一个字符。我发现
后文本更改中的
setText
使按住backspace键不起作用。 我不知道确切的机制,但似乎是
setText
push-up-backspace

此外,Android 7.0中似乎没有出现这种情况,但Android 8.0和9.0中出现了这种情况


提前谢谢你

使用此按钮可了解何时按下退格键:

editText.setOnKeyListener(new OnKeyListener() {                 
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    //You can identify which key pressed buy checking keyCode value with KeyEvent.KEYCODE_
    if(keyCode == KeyEvent.KEYCODE_DEL) {  
        editText.setText(editText.getText().tostring()); // gets the current text and sets it again
    }
    return false;       
}
});

你说它只工作一次。如果按此键,则可以再次设置文本,然后只能再按一次backspace。

只要按住backspace和上面的代码不起作用,我想删除字符。这里也有同样的问题!“你能弄明白吗?”刘文斌(不知道)。对不起,我找不到解决办法。我没有足够的时间深入研究此问题。我不确定问题的原因,但
editable.replace(0,editable.length,replacedText)
在某些情况下可能会有所帮助。供其他人参考。哦,忘了提及,如果您希望
可编辑,请不要在EditText上设置InputType
。替换(0,editable.length,replacedText)
有助于防止退格被推上。