Im trying to sort my ListView in alphabetic order. ListView has 3 fields: title, description, image
. I must sort title in alphabetic order.
Asked
Active
Viewed 118 times
0

Gavin Miller
- 43,168
- 21
- 122
- 188
-
Sort the contents of your data model. If you are using a `CursorAdapter`, add the appropriate sorting rule to your query (e.g., `ORDER BY` for SQLite). If you are using an `ArrayAdapter`, sort your `ArrayList` using `Collections.sort()`. And so on. – CommonsWare Sep 20 '15 at 13:36
1 Answers
1
sort your list (no the listView). try this:
Collections.sort(yourList, new Comparator<yourClass>() {
@Override
public int compare(yourClass left, yourClass right) {
return left.getTitle().compareTo(right.getTitle());
}
});

AsfK
- 3,328
- 4
- 36
- 73
-
I have class Fish,for Example.I must put "Fish" instead "yourClass" or ArrayList
> ? – Rostislav Prozorovsky Sep 20 '15 at 13:49 -
Yes. btw, FTI, if the returned list is immutable you should storage the result in new variable. see this link: http://stackoverflow.com/questions/32328630/unsupportedoperationexception-when-trying-sort-sensor-list – AsfK Sep 21 '15 at 08:16