Android java custom sorting using Comparable

后端 未结 3 1143
-上瘾入骨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:53

    Your ABC sort logic doesn't work. If you pass in two USER_TYPE_FRIEND objects for instance, whatever their respective order, compareTo will always return BEFORE.

    You need to implement this by first comparing the usertype.

    If they are equal, you can return your row.compareTo(...) expression.

    If not, you need to return before/after depending only on how those types "compare" in your logic (i.e. friend < normal < banned).

提交回复
热议问题