对此有任何帮助,确定它很简单,但看不到它。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