Reputation: 1434
I need a comparator, in Kotlin, to order every object that enter in my recycler view (using Fast Adapter).
I need to order the objects by an Integer, where the biggest ones come first.
The code above order the object that enters in my list, but the biggest ones is in the end of the list. Is there a way to reverse the order?
playersFastAdapter.itemAdapter.withComparator(compareBy({ it.player.goals }, {it.player.assists}), true)
Upvotes: 5
Views: 4650
Reputation: 96
mylist.sortWith(compareBy<Player> { it.name }.thenBy { it.age }.thenBy { it.gender })
or
mylist.sortWith(compareByDescending<Player> { it.name }
.thenByDescending { it.age }.thenBy { it.gender })
Upvotes: 8
Reputation: 1434
As suggested by Mitja Slenc on Kotlin forum:
Changed to compareBy({ -it.player.goals}, {-it.player.assists})
And now it's working the way I wanted!
Upvotes: 3