Android 遍历Hashmap里面的key 和value

     Android项目中需要将很多数据显示在一个listview上面,所以想到了使用hashmap的泛型来保存数据:

  HashMap listItem = new HashMap

    这时候需要先存入数据,然后要提取出来赋值给textview,以下是遍历key-value方法:

for (int i = 0; i < summaryMap.size(); i++) {
			listItem = new HashMap();

			Iterator> iter = summaryMap.entrySet()
					.iterator();
			while (iter.hasNext()) {
				listItem = new HashMap();
				@SuppressWarnings("rawtypes")
				Map.Entry entry = (Map.Entry) iter.next();
				// String instrument = (String) entry.getKey();
				SummaryStruct sumStru = (SummaryStruct) entry.getValue();
				
				listItem.put("instrument", sumStru.getInstrument());
				listItem.put("netLots", sumStru.getNetLots());
				listItem.put("netFloatPL", sumStru.getNetFloatPL());
				listItem.put("isNetBuysell", sumStru.isNetBuysell());
				listItem.put("sellLots", sumStru.getSellLots());
				listItem.put("bidPrice", sumStru.getBidPrice());
				listItem.put("sellFloatPL", sumStru.getSellFloatPL());

				listItem.put("buyLots", sumStru.getBuyLots());
				listItem.put("askPrice", sumStru.getAskPrice());
				listItem.put("buyFloatPL", sumStru.getBuyFloatPL());

				maps.add(listItem);
			}


你可能感兴趣的:(Android)