Android中列表排序问题Sort();常会报如下错误:The method sort(List, Comparator super T>) in the type Collections is not applicable for the arguments (List>, Comparator)
Sort()函数原型:
void java.util.Collections.sort(List list, Comparator super String> comparator)
正常情况可以这样排序:
Collections.sort(items,String.CASE_INSENSITIVE_ORDER);
如果List参数为这种样式:
List> list = new ArrayList>();
需要这样来排序,否则报错:
//从低到高排序,试试吧
Collections.sort(list, new Comparator>(){
@Override
public int compare(Map o1, Map o2) {
if((Boolean)o1.get("isDir") && !(Boolean)o2.get("isDir"))
return -1;
if(!(Boolean)o1.get("isDir") && (Boolean)o2.get("isDir"))
return 1;
return (((String)o1.get("title")).toLowerCase()).compareTo(((String)o2.get("title")).toLowerCase());
}
});