2017-04-11 63 views
0

嗨,我適配器如下排序適配器列表

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 ABC 安裝

BCD AAA 安裝

應該排序列表類似下面

應用與名稱和包名稱,並在頂部

+0

爲什麼不使用比較器接口 –

+0

你能舉個例子嗎?我完全困惑如何做到這一點我已經添加了兩個檢查首先檢查狀態,然後名稱和對齊現在變得困惑,以實現所有3合一 –

回答

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; 
      } 
     } 

地獄啊我是天才;) 完全混亂,但工作

首先檢查它的應用程序名稱然後它檢查安裝然後它檢查包名

你可以將安裝的代碼向上移動並打包使之反之亦然