I use a ListView with android.R.layout.simple_list_item_multiple_choice as list items. I want to sort the list (and maybe group the list) that checked items are on top of the list. I looked at the Comparator but it only lets me sort the list by the entries name of the list.
How could that be done in a nice way?
I use a ListView with android.R.layout.simple_list_item_multiple_choice as list items. I want to sort the
Share
Its not true that a Comparator can only Compare Strings. You could just extend Comparator yourself and compare your Objects. So if Your Object is “smaller” return -1 and if it is “greater” return 1, if equal 0.
I’m asuming you have a simple Object representing a row of your list, lets say ListItem.
Then You write
You could then sort your List with
function and fill them with your ListItems and an Instance of your Comparator.
after that tell the Adapter that you changed his Content