I have the next code for formatting text in TextChangedListener:
override fun afterTextChanged(edit: Editable?) {
editText?.removeTextChangedListener(this)
editText?.setText(getFormattedText(edit?.toString())
editText?.addTextChangedListener(this)
}
So initially I get the default input type which is ABC, now when I change it to ?123 type and after entering some number the keyboard changes back to ABC.
I tried to use Editable.replace() и Editable.append() but these methods under the hood do not preserve the state of the text. And in afterTextChanged(), the text doubles.
For example, I will enter "123" and call setText("12"), and the next time I enter, for example, "4", the text will come to afterTextChanged() - "1234" - "3" should not be
The question is - how to fix the keyboard reset?