Using Cursors with the new RecyclerView (CursorRecyclerAdapter)
19 Apr 2015Recently, I’ve decided to replace the ListViews in my application with the new RecyclerView. Using Cursor all over my application, I needed an equivalent of the CursorAdapter
class. I look up the the recycler-view support library hoping I would find something ready to use but unfortunately there wasn’t. I’ve found a couple third-party implementations of a “CursorRecyclerAdapter” and decided to use one.
A few weeks later, I was profiling my applications and noticed I had a memory problem. After using MAT to track down the leak, I realized the third-party class I included in my project was the culprit! Fixing the problem was easy, but I can’t help myself thinking about all the developers looking for a CursorRecyclerAdapter library who found this leaky one and used it in their apps without noticing the problem.
I’ve decided to create my own version and publish it for all the Android developers out there who need it. This library is intended to work with or without a CursorLoader. I have also implemented an equivalent of the SimpleCursorAdapter
class, named SimpleCursorRecyclerAdapter.
And here is the implementation of SimpleCursorRecyclerAdapter :