There is a spannable text input field. For it is necessary to change part of the text. I do this:

{ Editable editable = getText(); editable.replace(start, end, ""); } 

As a result, the text is deleted, but when you enter any character, the text returns to the very end of the input field.
I tried to add TextWatcher, in the end:

 @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { //Тут текст корректный, с удаленными символами } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { //А тут уже текст некорректный. Вырезанная строка добавляется в конец } @Override public void afterTextChanged(Editable s) { //Так же как в onTextChanged } 

It does not appear everywhere, while it is noticed only on Samsung tablets with Android 4.1.2. Why is this happening and what to do?

1 answer 1

Try before editing editable text removeTextChangedListener() and then add addTextChangedListener() again to get rid of recursive calls.

  • addTextChangedListener is not installed. Added it later and temporarily to find out at what point the text is added - Lexd5
  • @ Lexd5 And if you try to just get a String , replace it and make setText() ? - anber
  • I thought about it, tried it, but there is a problem with the fact that in Editable we have formatted text (underlined, repainted, etc.), when casting to String, this is all lost. - Lexd5