3

我正在开发一个可以向UserDictionary添加单词并从中查询的应用程序。在平板设备上运行应用程序时,它工作正常。但是在非平板设备上运行它并将自动更正的单词保存到我的单词列表并查询它时,它没有检索到单词。

所以我应该做些什么来查询和选择所有保存的自动更正的单词。

// this to add word to dictionary
    Uri dic = UserDictionary.Words.CONTENT_URI;
    UserDictionary.Words.addWord(this, "word", 100, UserDictionary.Words.LOCALE_TYPE_ALL);

// this to query 
         Uri dic = UserDictionary.Words.CONTENT_URI;
         ContentResolver resolver = getContentResolver();
         Cursor cursor = resolver.query(dic, null, null, null, null);
         while (cursor.moveToNext()){
            String word = cursor.getString(cursor.getColumnIndex(UserDictionary.Words.WORD));
            int id = cursor.getInt(cursor.getColumnIndex(UserDictionary.Words._ID));
            String app = cursor.getString(cursor.getColumnIndex(UserDictionary.Words.APP_ID));
            int frequency = cursor.getInt(cursor.getColumnIndex(UserDictionary.Words.FREQUENCY));
            String locale = cursor.getString(cursor.getColumnIndex(UserDictionary.Words.LOCALE));
            Log.i("", "word: "+word+"\nId: "+id+"\nAppID: "+app+"\nfrequency: "+frequency+"\nLocale: "+locale);
         }
4

1 回答 1

2

要添加单词,Javadoc建议使用 UserDicrionary.Words.addWord。

要使用拼写检查器,Android 4.0 以上有一个框架,以及一些使用示例。希望这些帮助。

于 2012-10-04T17:21:37.380 回答