Groupie: Save position state

Created on 15 Jun 2017  路  3Comments  路  Source: lisawray/groupie

Save Group scroll position state after data set change

help wanted

Most helpful comment

You don't have to do anything special for Groupie. You can just use the normal methods you would with any RecyclerView with a LinearLayoutManager or GridLayoutManager.

To save state:
int scrollPosition = layoutManager.findFirstVisibleItemPosition()

To restore state:
layoutManager.scrollToPosition(scrollPosition)

All 3 comments

You don't have to do anything special for Groupie. You can just use the normal methods you would with any RecyclerView with a LinearLayoutManager or GridLayoutManager.

To save state:
int scrollPosition = layoutManager.findFirstVisibleItemPosition()

To restore state:
layoutManager.scrollToPosition(scrollPosition)

@lisawray thanks!

Using the above method if you have more items on your group the view will snap to start of the group. To overcome this you could use layoutManager.onSaveInstanceState()

To save state:
Parcelable layoutManagerState = layoutManager.onSaveInstanceState();

To restore state:
layoutManager.onRestoreInstanceState(layoutManagerState);

Kudos

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rpedretti picture rpedretti  路  3Comments

forntoh picture forntoh  路  3Comments

lisawray picture lisawray  路  7Comments

andhie picture andhie  路  3Comments

mattinger picture mattinger  路  3Comments