prabu prabu - 1 month ago 30
Android Question

How to sort or arrange the items of a listview in android?

Can any one tell me how to sort or arrange the items of a listview in android?
I've searched it for through Google, but i coudn't find any simple program to do that.
Has any one have at-least one sample program to achieve this concept?

Suggestions please..

Thanks for your precious time!..

Answer

Use comparator for sorting like

Collections.sort(data, new Comparator<YourDataModel>() {
    @Override
    public int compare(YourDataModel data1, YourDataModel data2) {
          if( data1.getDistance() < data2.getDistance() )
             return 1;
          else
             return 0;
    }
});

Where data is my array with the items inside.

For more refer the below link

http://stackoverflow.com/a/16353013/2143817