Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android sort ArrayLit<class> in API16?

I´m doing an assignment and it´s required to support API16.

My view is a custom ArrayListAdapter with takes an

ArrayList<someclass>

The problem is that I want to make it possible to sort the data the user has put in the list.

items.sort(new Comparator<someclass>() {
    @Override
    public int compare(someclass item1, someclass item2) {
        return item1.Name.compareTo(item2.Name);
    }
});

But when I try Android Studio tells that I need API 24.

how do I sort the list in API 16?

like image 742
ZeroKat Avatar asked Mar 28 '18 13:03

ZeroKat


1 Answers

You can use Collections.sort

Collections.sort(items, new Comparator<someclass>() {
    @Override
    public int compare(someclass item1, someclass item2) {
        return item1.Name.compareTo(item2.Name);
    }
});
like image 113
lelloman Avatar answered Nov 15 '22 06:11

lelloman