【发布时间】:2015-08-25 04:46:34
【问题描述】:
如何获取哈希映射数组列表的索引,这是我的代码
ArrayList<HashMap<String, String>> branch_list=new ArrayList<HashMap<String,String>>();
branch_list.clear();
Log.d("kkk", "sew1="+Constants.questions_arr_list+" size="+Constants.questions_arr_list.size());
Cursor cs1 = db.rawQuery("SELECT * from questions WHERE page_sequence='"+onValue+"' and survey_id='"+Constants.survey_id+"' ORDER BY question_sequence ASC",null);
if (cs1.moveToFirst()) {
do {
if (cs1.getString(27).matches("0")) {
HashMap<String, String> map=new HashMap<String, String>();
map.put("id", "" + cs1.getString(0));
map.put("survey_id", "" + cs1.getString(25));
map.put("title", "" + cs1.getString(12));
map.put("type_id", "" + cs1.getString(24));
map.put("required", "" + cs1.getString(7));
map.put("others", cs1.getString(53));
map.put("page_yes", cs1.getString(1));
map.put("page_no", cs1.getString(2));
map.put("page_dontno", ""+cs1.getString(54));
map.put("branching_status", ""+cs1.getString(55));
branch_list.add(map);
Constants.questions_arr_list.add(map);
Constants.questions_arr_list_copy.add(map);
} else {
}
if (cs1.getString(55).matches("1")) {
break;
}
} while (cs1.moveToNext());
} else {
}
下面是我获取值后的数组列表。我想获取 id=2572 的索引, 比如答案=2。
[{id=2570, title=第 1 页问题 01, others=0, page_yes=0, branching_status=0, page_no=0, required=0,survey_id=592, type_id=1, page_dontno=0}, { id=2571, title=第1页问题02, others=0, page_yes=0, branching_status=0, page_no=0, required=0,survey_id=592, type_id=9, page_dontno=0}, {id=2572, title=第 1 页问题 03 分支问题, others=0, page_yes=2, branching_status=1, page_no=3, required=0,survey_id=592, type_id=8, page_dontno=0}, {id=2575, title=Page 2 Question 01, others=0, page_yes=0, branching_status=0, page_no=0, required=0,survey_id=592, type_id=23, page_dontno=0}, {id=2576, title=Page 2 Question 02 Branching Question, others=0, page_yes=5, branching_status=1, page_no=0, required=0,survey_id=592, type_id=9, page_dontno=0}]
【问题讨论】:
-
为什么HashMap需要索引?地图使用“键”来访问数据,而列表将允许您基于索引进行查找。
-
看起来你需要遍历你的列表。意味着通过循环读取每个列表项。