我想要做類似的事情。我提出的解決方案是使用SpellCheckerSession,並檢查它是否與onGetSentenceSuggestions中的完全匹配。
public class SpellChecker implements SpellCheckerSessionListener {
public SpellChecker(Activity a)
{
final TextServicesManager tsm = (TextServicesManager) a.getSystemService(
Context.TEXT_SERVICES_MANAGER_SERVICE);
SpellCheckerSession scs = tsm.newSpellCheckerSession(null, null, this, true);
TextInfo[] tia = {new TextInfo("trewgjj"), new TextInfo("great")};
scs.getSentenceSuggestions(tia, 3);
}
@Override
public void onGetSuggestions(SuggestionsInfo[] results) {
// TODO Auto-generated method stub
}
@Override
public void onGetSentenceSuggestions(SentenceSuggestionsInfo[] results) {
for (int i = 0; i < results.length; ++i) {
// Returned suggestions are contained in SuggestionsInfo
for (int j = 0; j < results[i].getSuggestionsCount(); ++j) {
SuggestionsInfo si = results[i].getSuggestionsInfoAt(j);
if ((si.getSuggestionsAttributes() & SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY) != 0)
Log.d("", "EXACT MATCH FOUND");
}
}
}
}
唯一的問題是,如果你也想驗證對用戶定義的字典中的單詞。我不相信這些拼寫檢查框架中包含這些內容,因此您可能需要手動檢查這些詞語。