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?
views:
336answers:
1
+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
2010-08-20 21:51:21
How would I apply the ViewHolder pattern? Would I split it between newView() and bindView() ?
Scienceprodigy
2010-08-20 22:09:53
@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
2010-08-20 22:24:37
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
2010-08-20 22:53:38
@Scienceprodigy: If you have 2+ types of rows, you need to override `getViewTypeCount()` and `getItemViewType()`.
CommonsWare
2010-08-21 06:40:19