首先需要如下方法
/**
* 根据最后一条消息的时间戳对对话进行排序
* 使用时将T替换成你要排序的Bean对象
*
* @param 需要排序的list
*/
private void sortTime(List<Pair<Long, T>> list) {
Collections.sort(list, new Comparator<Pair<Long, T>>() {
@Override
public int compare(final Pair<Long, T> con1, final Pair<Long, T> con2){
if (con1.first.equals(con2.first)) {
return 0;
} else if (con2.first.longValue() > con1.first.longValue()) {
return 1;
} else {
return -1;
}
}
});
}
引用如下方法实现排序
/**
* 加载对话列表
* T 替换为你要排序的Bean对象
* t.getMsgTime() 为按时间排序的字段,实际使用时替换为你要排序的字段
*
* @return
*/
protected List<T> loadList(List<T> listT) {
Map<String, T> lists