vendredi 22 mai 2015

How to show data from database into a RecyclerView with high performance?

I wrote my own CursorAdapter for RecyclerView like following link: http://ift.tt/1APppfF

Then I found whenever I change something in database and want to show it in RecyclerView, I need to create a new Cursor by db.query() and use CursorAdpater's changeCursor(). Since query() will scan all rows in database, the RecyclerView will refresh slowly when data amount is big even I insert only one row into database.

Besides, as we all know, RecyclerView provides notifyItemInserted/Removed(position) for developers so that the RecyclerView can refresh partly, which is useful and beneficial to memory/time. However, when I use CursorAdapter, I don't know when and how I can use these methods because changing cursor isn't adding something directly to dataset binding with RecyclerView but refreshing all items in fact.

So are there any better ways to show data from database in RecyclerView and use RecyclerView's improving method to show variety of database?

Aucun commentaire:

Enregistrer un commentaire