先是从数据库中获取所有的值,返回一个HashMap类型的数据:
<pre name="code" class="java"> private HashMap<String, String> searchSql() {
int columnsSize = cursor.getColumnCount();
HashMap<String, String> map = new HashMap<String, String>();
if (cursor != null) {
while (cursor.moveToNext()) {
System.out.println("设备名称ID " + cursor.getString(1)
+ "<--------->" + cursor.getString(0));
for (int i = 0; i < columnsSize; i++) {
map.put(cursor.getString(1), cursor.getString(0));
}
}
}
return map;
}
然后保存包
<pre name="code" class="java"> HashMap<String, String> map =searchSql();//返回的map
List<String> keyList = new ArrayList<String>(map.keySet());
List<String> valueList = new ArrayList<String>(map.values());
for(int i = 0; i < map.size(); i++){
System.out.println("测试 " + valueList.get(i));
tableView.addBasicItem(new BasicItem(keyList.get(i),valueList.get(i) , false));//用的UItable开源控件,显示在listview中
}