Answer the question
In order to leave comments, you need to log in
How to work with android autocorrect in EditText?
Hello.
I encountered the problem that when autocorrecting the input text, when a line break or space is pressed (in general, when the autocorrect function performs autocorrect), the old string is passed to the afterTextChanged function (TextWatcher interface function), without new space or line break characters.
I use the standard android keyboard on the screen.
Tell me how to work with autocorrect?
Answer the question
In order to leave comments, you need to log in
AutoCorrect works according to the principle:
First, replace the word that is being edited (even if the replacement occurs with the same word)
Then add an end-of-word character (space, paragraph, etc.)
I don’t know why this was done.
In accordance with this principle, afterTextChanged first gets the line with the replaced word and immediately after it the line with the new character (afterTextChanged is called twice).
And here there is one subtlety. If during the first call to afterTextChanged the content of editText is changed (for most TextView descendants), then the second call with the addition of the end-of-word character will not occur.
And since it is impossible to directly intercept characters from the virtual keyboard (except to connect to it, but I don’t know if this is possible and how this is done.), it’s not possible to find out whether a regular replacement or a replacement due to the end of a word occurs (at least I did not find a way, this does not mean that it does not exist).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question