質問

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.

役に立ちましたか?

解決

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.

他のヒント

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top