2012-10-01 20 views
3

我正在開發一個應用程序,可以將單詞添加到UserDictionary並從中進行查詢。 在平板設備上運行應用程序時,它工作正常。 ,但在非平板設備上運行它 並將自動更正的單詞保存到我的單詞列表並查詢它時,它不檢索單詞。如何在android字典中獲取保存的單詞

所以我應該做什麼來查詢和選擇所有保存的自動糾正的單詞。

// 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); 
     } 
+0

你是什麼意思'它沒有檢索詞'?日誌是空的?您應該將其保存在「List」中供以後使用。 – Aprian

+0

@Aprian我知道,但我的意思是自動更正的詞,我把它保存在android選項卡中,它保存到UserDictionay,但在其他Android設備它沒有保存到UserDictionary,所以我想知道如何獲取保存的字。 –

回答

2

要添加一句話,Javadoc建議使用UserDicrionary.Words.addWord。

要使用Android 4.0以上的拼寫檢查程序,有一個framework以及幾個使用示例。希望這些幫助。