【发布时间】:2012-08-22 06:40:51
【问题描述】:
我的价值观是
问题 Q-id
第一季度 1
第二季度 2
...等等
我想通过调用函数来检索它们。所以我使用了一个HashMaps的arraylist,如下所示..
public ArrayList<HashMap<String,String>> getAllQuestions(Integer id)
{
try
{
HashMap<String,String> QuesList = new HashMap<String,String>();
ArrayList<HashMap<String, String>> QuestionArrayList = new ArrayList<HashMap<String, String>>();
// Select All Query
String selectQuery = <some query here>;
cursor = mDb.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor.moveToFirst())
{
do
{
QuesList.put("ques_id", cursor.getString(2));
QuesList.put("ques_text", cursor.getString(8));
QuestionArrayList.add(QuesList);
Log.i("ques",cursor.getString(8) );
} while (cursor.moveToNext());
}
Log.i("check"," Ques list returned");
return QuestionArrayList;
}
catch (SQLException mSQLException)
{
Log.e(TAG, "getTestData >>"+ mSQLException.toString());
throw mSQLException;
}
}
现在 Logcat 显示在单个提取时成功检索了所有问题(如 Log.i 语句所示),但是当我在最后运行以下循环时,所有元素都被最后一个提取的问题替换。非常感谢任何帮助。
for(HashMap<String, String> t : QuesList )
{
Log.d("out there", "count" + t.getString());
Log.i("mapping....",t.get("ques_id"));
}
【问题讨论】: