ZeroKat
ZeroKat

Reputation: 135

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?

Upvotes: 9

Views: 1028

Answers (1)

lelloman
lelloman

Reputation: 14183

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);
    }
});

Upvotes: 14

Related Questions