devunwired / recyclerview-playground

Examples of RecyclerView use and custom LayoutManager implementations
MIT License
1.24k stars 269 forks source link

Example with content providers instead of an array list #18

Closed cesine closed 9 years ago

cesine commented 9 years ago

Hi @devunwired

Thanks for your talk at MTL DroidCon, it was awesome! I finally had some time to look back into updating one of my listviews into a recyclerview. I tried a few things but nothing displayed, so I thought maybe I should see how pulling from a database could look by tweeking your example to pull from a cursor/content provider instead of an array list. The result is this branch if you want it.

Summary of changes

There are a couple of things which are funky, most notably that once the db no longer has a 1-to-1 relation with array list positions (ie you add and remove a few items) the order display is not what you expect because the view still thinks of things as an expanding and contracting always full array, and tries to get items at x position. To change this would require changing more of the original code outside of the adapter. But this was still a good exercise for me to see how the adapter are used.

devunwired commented 9 years ago

I greatly appreciate the effort that went into this, and your willingness to contribute it back. However, I think the code distracts from the core intent of the sample, which is to explain custom layout behavior in RecyclerView. All other code (such as adapters) is really the minimal amount of boilerplate required to make the sample functional.

I will certainly bookmark your repo for myself if I ever need to incorporate a Cursor in my own projects!

cesine commented 9 years ago

no prob :)