我想要它:
我的代码仅适用于ASCENDING,在降序时,字符串在空字符之前。
SECOND_SORT {
public int compare(String s1, String s2) {
if (s1.equals("") && s2.equals("")) {
return 0;
}
if (s1.equals("")) {
return -1;
}
if (s2.equals("")) {
return 1;
}
return s1.compareTo(s2);
}
这是排序..
if (mSortingIdentifier == SortingIdentifier.DESC) {
Collections.sort(list, Comparator.descending(Comparator.getComparator(Comparator.FIRST_SORT, Comparator.SECOND_SORT)));
} else {
Collections.sort(list, Comparator.ascending(Comparator.getComparator(Comparator.FIRST_SORT, Comparator.SECOND_SORT)));
}
答案 0 :(得分:0)
我找到了一个有效的解决方案.. 我刚刚添加了另一个SECOND_SORT_DESC,我在适配器中交换返回值..当我排序时,我检查它的ASC或DESC并使用我想要的枚举...
供参考:
SECOND_SORT_ASC {
public int compare(String s1, String s2) {
if (s1.equals("") && s2.equals("")) {
return 0;
}
if (s1.equals("")) {
return -1;
}
if (s2.equals("")) {
return 1;
}
return s1.compareTo(s2);
},
SECOND_SORT_DESC {
public int compare(String s1, String s2) {
if (s1.equals("") && s2.equals("")) {
return 0;
}
if (s1.equals("")) {
return 1;
} // swapped these two
if (s2.equals("")) {
return -1;
}
return s1.compareTo(s2);
} // Here is where I differ between asc and desc
if (mSortingIdentifier == SortingIdentifier.DESC) {
Collections.sort(list, Comparator.descending(Comparator.getComparator(Comparator.FIRST_SORT, Comparator.SECOND_SORT_DESC)));
} else {
Collections.sort(list, Comparator.ascending(Comparator.getComparator(Comparator.FIRST_SORT, Comparator.SECOND_SORT_ASC)));
}