Error : Adapter needs to have stable IDs so that the expanded item can be restored across orientation changes.
SourabhSNath opened this issue · comments
What is this error? I replaced my RecyclerView as shown in the example, but this error occurs. This error is also shown on the layout xml, I tried building the project anyway.
My RecyclerView is in a fragment, does that matter? Should I only use this on an activity?
Stable IDs are required because while the content page is expanded, its associated list item's position can change in the adapter. When the page has to collapse, InboxRecyclerView
finds the associated list item again in case its position has changed to avoid collapsing to the wrong location.
To make this work, you'll have to do two things:
- Override
getItemId()
in your adapter and calculate an ID for each item. - Call
setHasStableIds(true)
on your adapter.
Closing this due to inactivity. Feel free to re-open this.