Hi i Adapter如下
public class ApplicationInfo implements Comparable<ApplicationInfo> {
public String name;
public String packageName;
public String status;
public Drawable icon;
@Override
public int compareTo(ApplicationInfo another) {
MainActivity cls = new MainActivity();
cls.sort(ApplicationContext.getAppContext());
if (cls.sort(ApplicationContext.getAppContext()) == 1){
return name.compareToIgnoreCase(another.name); // ascending
}else if (cls.sort(ApplicationContext.getAppContext()) == 2){
return another.name.compareToIgnoreCase(name); // descending
} else if (cls.sort(ApplicationContext.getAppContext()) == 3){
if(status.equals(another.status)){
return name.compareToIgnoreCase(another.name);
}else {
return status.equals("Not Installed") ? 1 : -1; // installed up along with ascending names
}
} else if (cls.sort(ApplicationContext.getAppContext()) == 4){
if(status.equals(another.status)){
return name.compareToIgnoreCase(another.name);
}else {
return status.equals("Installed") ? 1 : -1; // not installed up along with ascending names
}
} else
return this.name.compareToIgnoreCase(another.name); // ascending
}
}
现在我想做的是我还想根据包名添加排序,包括名称和安装状态
例如
排序1和2使名称升序和降序
并排序3和4首先检查名称,然后检查状态
现在我想要的是排序5和6检查名称然后检查安装状态(与3和4相同,这是正常工作)并检查包名称
所以,如果应用程序是
ABC A.B.C 安装
BCD a.a.a 安装
它应该对列表进行排序,如下所示
带名称和包名称且位于顶部的应用
答案 0 :(得分:0)
我让它运作良好
if(status.equals(another.status) && packageName.equals(another.packageName)){
return name.compareToIgnoreCase(another.name);
}else {
if(status.equals(another.status) && !packageName.equals(another.packageName)){
return packageName.compareToIgnoreCase(another.packageName) ? 1 : -1;
}else{
return status.equals("Installed") ? 1 : -1;
}
}
地狱,是的,我是天才;) 完全令人困惑但工作
首先检查应用程序名称,然后检查已安装,然后检查包名称
你可以移动已安装的代码并打包以使其反之亦然