https://kotlinlang.org logo
#android
Title
# android
s

Schadenfreude

10/17/2019, 12:44 PM
Hey, everyone, I’ve been trying to find a way to reverse the order of the items in a paged list (or its data source) but I’m having 0 luck and can’t find any articles on how to do that. Does anyone know a way to achieve this?
a

Alexander

10/17/2019, 12:50 PM
Something like this?
Copy code
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
linearLayoutManager.setReverseLayout(true);
linearLayoutManager.setStackFromEnd(true);
myRecyclerView.setLayoutManager(linearLayoutManager);
s

Schadenfreude

10/17/2019, 1:01 PM
Sadly I’m using a GridLayoutManager so setStackFromEnd is not applicable :S
I’m currently using Paging Library with Room DB, my query looks like this:
Copy code
@Query("SELECT * from NOTES ORDER BY creationDate DESC")
    fun getAllNotesDesc(): DataSource.Factory<Int, Note>
I tried a switch/case for DESC/ASC sort, but that also doesn’t work.
I also tried sorting the PagedList before submitting it to the Adapter, but I get an exception, it seems the PagedList is immutable.
s

Shahjahan

10/17/2019, 1:08 PM
GridLayoutmanager is child class of linearlayout manager so this method be available for grid layout manager as well
s

Schadenfreude

10/17/2019, 2:25 PM
Copy code
java.lang.UnsupportedOperationException: GridLayoutManager does not support stack from end. Consider using reverse layout
and only using reverse layout doesn’t have the desired effect
12 Views