如何在android字典中获取保存的单词

时间:2012-10-01 05:54:21

标签: android dictionary

我正在开发一个可以向 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);
         }

1 个答案:

答案 0 :(得分:2)

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

要使用Android 4.0以上的拼写检查程序,有一个framework,以及一些使用它的示例。希望这些帮助。