我需要最简单和优雅的方式(有了这个词)来检查给定的单词是否已经在用户词典中可用.字频率无关紧要,语言环境确实如此.
有没有什么比查询ContentResolver迭代和检查cursor.getString(INDEX_WORD).equals(myWord)更简单?
最佳答案 您应该创建一个查询,它将在UserDictionary中搜索您的单词:
getContentResolver().query(UserDictionary.Words.CONTENT_URI,
new String[]{UserDictionary.Words._ID, UserDictionary.Words.WORD},
//Selection
UserDictionary.Words.WORD +" = ?",
//Selection args
new String[]{myWord}, null);
比你可以检查光标:
if(cursor.getCount()==0){
//Word is not in dictionary
}