Android java custom sorting using Comparable

后端 未结 3 1134
-上瘾入骨i
-上瘾入骨i 2021-01-20 11:11
  @Override
      public int compareTo(final myRow another) {

        final int BEFORE    =-1;
        final int EQUAL     = 0;
        final int AFTER     = 1;

           


        
3条回答
  •  醉梦人生
    2021-01-20 11:54

    my code now :

      public enum user_type {USER_TYPE_FRIEND(1), USER_TYPE_NORMAL(2), USER_TYPE_BANNED(3);
          private final int order;
          user_type(int order) {
              this.order = order;
          }
          public int getOrder() {
              return this.order;
          }
      }
    

    ...

      @Override
      public int compareTo(final myRow another) {
    
        if (sorttype==sort_type.SORT_ABC) {
            if (this.getUserType().equals(another.getUserType())) {
                return this.getRow().toLowerCase().compareTo(another.getRow().toLowerCase());
            } else {
                return this.getUserType().compareTo(another.getUserType());
            }
        } 
        else {
            //LOGINTIME
            return this.getUserType().compareTo(another.getUserType());
        }
      }
    

    Thanks, Sanjay!

提交回复
热议问题