My RecyclerView
by defaults shows items sorted by name (that's how they come out of the database). I'am offering 4 additional sort options in the action bar for the users. I'm thinking of having 5 lists in the RecyclerView
one for each sort and another list (just a reference) to point to the current list. When new data arrives the lists get sorted appropriately and when the user selects a sort order the current list gets the appropriate value and I call notifyDataSetChaged()
. Is this a reasonable approach?
Asked
Active
Viewed 42 times
1

dfasdflskladf
- 101
- 1
- 6
-
1Generally you'd just keep one list, sort it, and do a notifyDataSetChanged afterwards. Nothing prevents your solution form working, it just takes several times the ram. – Gabe Sechan Dec 05 '18 at 15:51
-
@Gabe Sechan You're right and I feel embarrassed now. – dfasdflskladf Dec 05 '18 at 16:13
1 Answers
0
You don't need to have multiple lists one list is enough. You just have to order it as you want then replace it in your adapter then call notifyDataSetChanged() To sort your data you can use Comparator like in here : How to sort an ArrayList in Java Hope it helps

Master Fathi
- 349
- 1
- 9
- 19
-
Yeah actually I was a bit afraid because I tried to call `sort` on the list and it told me it needed API 24 to do that. Fortunately `Collections.sort` does work. – dfasdflskladf Dec 05 '18 at 16:16
-