comalex3
comalex3

Reputation: 2606

Why there is no cursor adapter for RecyclerView?

I found a working cursorAdapter for RecyclerView gist. It works similarly as for listView. But I can't understand why there is no default cursor adapter. It is bad practice using cursor adapter and need manually get data from db convert to list of objects and then use it? Or what explanation for this?

Upvotes: 1

Views: 250

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007286

But I can't understand why there is no default cursor adapter

Google elected not to create any concrete adapters for specific types of data collections.

You are certainly welcome to use a Cursor as the model data for a RecyclerView.Adapter. Just bear in mind that a Cursor treats the position as internal state. Make sure that your RecyclerView.ViewHolder pulls the data out of the Cursor and uses it, rather than holding onto the Cursor itself and assuming that it will always automatically be pointing to the correct row.

This sample app demonstrates a RecyclerView backed by a Cursor, in this case a Cursor obtained from querying the MediaStore ContentProvider.

Upvotes: 1

Related Questions