I have a RecyclerView
with an RecyclerView.Adapter
whose backing data is coming from a Cursor
via a Loader
. The data contains two types of items: A
and B
returned via an UNION ALL
. getItemViewType
returns different int
s for each (see note below). The A
and B
entities are from different SQLite database tables, and both theirs _id
start from 1
, so it's very like that there'll be a B
whose _id
is the same as an existing A
and vice versa.
Is it safe to set setHasStableIds(true)
on the above adapter?
It it possible that a weird case might happen when the cursor has both As and Bs with the same ID and an animation or recycle goes wrong?
Note:
All the other parts of the Adapter
is pretty standard: getItemViewType
is implemented by returning R.layout.a_view
or R.layout.b_view
. There are also separate ViewHolder
subclasses for each type created in onCreateViewHolder
with a switch on itemViewType
.
All items are displayed correctly and even animate when I go away to another activity, modify some data and then press the back button (thanks to Loaders I guess).