我尝试了好几个小时,但是没有找到最佳方法来实现HashMap的反向迭代,这是我拥有的HashMap。
Map<Integer, List<String>> map = new HashMap<Integer, List<String>>();
for(Integer key : map.keySet()) {
List<String> value = map.get(key);
List<Map<String,?>> security = new LinkedList<Map<String,?>>();
for(int ixy = 0; ixy < value.size()-1; ixy++){
security.add(createItem(value.get(ixy), value.get(ixy+1)));
}
adapter.addSection(Integer.toString(key), new SimpleAdapter(getApplicationContext(), security, R.layout.list_complex, new String[] { ITEM_TITLE, ITEM_CAPTION }, new int[] { R.id.list_complex_title, R.id.list_complex_caption }));
}
我也看过TreeMap的例子,
Map<Integer, List<String>> sortedMap = new TreeMap<Integer, List<String>>(map);
但是treemap也是按升序排列的,我想要的是按降序排列。