views:

336

answers:

1

So, I'm watching this video http://www.youtube.com/watch?v=N6YdwzAvwOA and Romain Guy is showing how to make more efficient UI adapter code using the getView() method. Does this apply to CursorAdapters as well? I'm currently using bindView() and newView() for my custom cursor adapters. Should I be using getView instead?

+2  A: 

CursorAdapter has an implementation of getView() that delegates to newView() and bindView(), in such a way as enforces the row recycling pattern. Hence, you do not need to do anything special with a CursorAdapter for row recycling if you are overriding newView() and bindView().

CommonsWare
How would I apply the ViewHolder pattern? Would I split it between newView() and bindView() ?
Scienceprodigy
@Scienceprodigy: In `newView()`, you would create the `ViewHolder` for the row and associate it with `setTag()`. In `bindView()`, you would retrieve the `ViewHolder` via `getTag()`.
CommonsWare
Thanks, that works. I'm having a bit of trouble with the recycling of the views though, because I have list items that have a header that is GONE by default, which I use to display dated sections. Everything shows up fine until I fling the list up or down, then there's headers showing up where they shouldn't be.
Scienceprodigy
@Scienceprodigy: If you have 2+ types of rows, you need to override `getViewTypeCount()` and `getItemViewType()`.
CommonsWare