Question

I have an EditText view with the spell checker activated. If there is a misspelled word, the word is redlined and a list of suggestions is displayed in a drop down menu. How can I programmatically find the list of misspelled words and the suggestion list for each of them? Note it is EditText, not AutoCompleteTextView.

Était-ce utile?

La solution

Here is an easy way to find the suggestions:

Spannable str = myEditText.getText(); 
SuggestionSpan[] spanned = str.getSpans(startIndex, endIndex, SuggestionSpan.class);

If spanned is not empty, there is an error in the text between startIndex and endIndex. By changing the values of these indices, it will be possible to find which word is erroneous. Each item in the spanned array has a field called mSuggestions, which is an array of strings and provides the suggested words for the erroneous word.

Autres conseils

This is kind of a guess, but I'd take a look at the Android spellchecker classes and finally at the EditText sourcecode.

The way it could work is by simply getting the text using getText() and then run the spellchecker again by yourself.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top