0

I am using Comparator to sort my ListView, but it doesn't work.

My code:

Collections.sort(orgi, new Comparator<Loc>() {

                @Override
                public int compare(Loc lhs, Loc rhs) {

                    if( lhs.getDist() < rhs.getDist() )
                         return 1;
                      else
                         return 0;
                }
            });

Can anyone suggest a solution?

M-Wajeeh
  • 17,204
  • 10
  • 66
  • 103
gIrL
  • 139
  • 4
  • 15

1 Answers1

3

Try this:

Collections.sort(orgi, new Comparator<Loc>() {

            @Override
            public int compare(Loc lhs, Loc rhs) {
                if(lhs.getDist() < rhs.getDist()){
                     return -1;
                 } else if(lhs.getDist() > rhs.getDist()){
                     return 1;
                 } else {
                     return 0;
                 }
            }
        });
M-Wajeeh
  • 17,204
  • 10
  • 66
  • 103
  • Thanks a lot, its working now :).. i was returning the wrong values. am such a dumb ;P. thanks. – gIrL Nov 14 '13 at 11:38
  • @user2978175 I am glad that your problem was solved but simply thanking is not the way to go on Stackoverflow. You must accept one of the answers if it helped you. – M-Wajeeh Nov 14 '13 at 12:53