I have a list with LongSparseArray<Object> . Everything works very well, the Object is updated key and redrawn. And now we have set the task, sort the list, by int , this is one of the fields in Object . I usually do this through Collections , what about SparseArray ? I really want to know how you do this task. I tried HashMap , but it seems to me there is no unique solution, it all comes down to sorting all the elements.

    1 answer 1

    The easiest option is to get an ArrayList and fill it with keys from LongSparseArray. Sort by comparator:

     (o1, o2) -> return lsa.get(o1).getFooProperty().compareTo(lsa.get(o2).getFooProperty()); 

    And recyclerView rebuild on ArrayList'u, getting the elements lsa.get(arrayList.get(position)) ...

    But of course the question arises, given that you tried with a hashmap, why not try it with ArrayList right away? In other words, where do you get the LongSparseArray and what is the purpose of its use, if it is obviously not suitable for the task?