我有价值观
问题 Q-id
Q1 1
Q2 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"));
}