我正在使用Comparator
对ListView
进行排序,但它不起作用。
我的代码:
Collections.sort(orgi, new Comparator<Loc>() {
@Override
public int compare(Loc lhs, Loc rhs) {
if( lhs.getDist() < rhs.getDist() )
return 1;
else
return 0;
}
});
有人可以建议解决方案吗?
答案 0 :(得分:3)
试试这个:
Collections.sort(orgi, new Comparator<Loc>() {
@Override
public int compare(Loc lhs, Loc rhs) {
if(lhs.getDist() < rhs.getDist()){
return -1;
} else if(lhs.getDist() > rhs.getDist()){
return 1;
} else {
return 0;
}
}
});