private void sortTime(HashMap<Integer, AlarmClockBean> mData) { List<Map.Entry<Integer, AlarmClockBean>> infoIds = new ArrayList<Map.Entry<Integer, AlarmClockBean>>(mData.entrySet()); Collections.sort(infoIds, new Comparator<Map.Entry<Integer, AlarmClockBean>>() { public int compare(Map.Entry<Integer, AlarmClockBean> o1, Map.Entry<Integer, AlarmClockBean> o2) { DateFormat f = new SimpleDateFormat("HH:mm"); String o11 = o1.getValue().getDingTime(); String o22 = o2.getValue().getDingTime(); try { return f.parse(o11).compareTo(f.parse(o22)); } catch (ParseException e) { throw new IllegalArgumentException(e); } } }); mData.clear(); int k = 0; for (Map.Entry<Integer, AlarmClockBean> item : infoIds) { int i = item.getKey(); mData.put(k,infoIds.get(k).getValue()); k++; } }
Android 定时时间列表排序
最新推荐文章于 2024-07-30 20:50:32 发布