對此有任何幫助,確定它很簡單,但看不到它。ContentValues數組中的重複ContentValues
做一個bulkInsert到內容提供者(UserDictionary),但所有插入有相同的「字」值。問題是ContentValues數組。 這是一些測試代碼,我有:
public void mClick(View v){
int batchSize = 25;
ContentValues[] mValueArray = new ContentValues[batchSize];
List<ContentValues>mValueList = new ArrayList<ContentValues>();
ContentValues mNewValues = new ContentValues();
mNewValues.put(UserDictionary.Words.APP_ID, this.getPackageName());
mNewValues.put(UserDictionary.Words.LOCALE, "en");
mNewValues.put(UserDictionary.Words.FREQUENCY, "255");
mNewValues.put(UserDictionary.Words.WORD, "WORD1");
mValueList.add(mNewValues);
mNewValues.put(UserDictionary.Words.APP_ID, this.getPackageName());
mNewValues.put(UserDictionary.Words.LOCALE, "en");
mNewValues.put(UserDictionary.Words.FREQUENCY, "255");
mNewValues.put(UserDictionary.Words.WORD, "WORD2");
mValueList.add(mNewValues);
mValueArray = new ContentValues[mValueList.size()];
mValueList.toArray(mValueArray);
Log.i(TAG,mValueList.toString());
Log.i(TAG,mValueArray[0].toString());
Log.i(TAG,mValueArray[1].toString());
}
和日誌,可以看出,mValueArray有重複的值。
02-22 12:33:51.060: I/log(859): [appid=dictionary word=WORD2 frequency=255 locale=en, appid=dictionary word=WORD2 frequency=255 locale=en]
02-22 12:33:51.070: I/log(859): appid=dictionary word=WORD2 frequency=255 locale=en
02-22 12:33:51.070: I/log(859): appid=dictionary word=WORD2 frequency=255 locale=en
顯然我在向數組中添加值時做了一些不正確的事情。誰能幫我? 感謝
爲什麼你想要轉換爲數組呢?只需使用* mValueList * ... – m0skit0 2012-02-22 12:51:06
轉換爲數組是因爲bulkInsert不接受arrayList。謝謝@ m0skit0 – user1094747 2012-02-23 10:22:06