I was using some of the code from DeskClock and found that when I tried to modify the CursorAdapter that newView was getting called for each item. (I actually wanted to add a divider and it seems like adding the dividers separately is better than adding them into a single listView)
If I have 3 items I get the following behavior:
newView - called with item: 0 bindView - called with item: 0 bindView - called with item: 1 bindView - called with item: 2 bindView - called with item: 0 newView - called with item: 1 bindView - called with item: 1 newView - called with item: 2 bindView - called with item: 2 newView - called with item: 0 bindView - called with item: 0 bindView - called with item: 1 bindView - called with item: 2
I would've expected newView/bindView to be called once per cursor item. But, that doesn't seem to be the case. This was kind of a problem for me because I wanted to select the appropriate view depending on the cursor data, but since bindView could be called before newView that doesn't work.
Is this some odd recycler behavior (or somehow normal/expected)? Or is there something broken with the code (I removed everything except the ListView and it's still doing this)? I'm not quite sure why you would try to bind views that haven't been created, and why newView gets called on the first item twice.
Thanks!
Btw, if someone has an easy way of adding dividers to ListViews I'd love to know. I was going to try to dig through the contacts example to see how they did it there if not.
Btw, in case anyone's wondering MergeAdapter was neat to mess around with and try (I'll use it in some other situations). But, I did just end up writing a single adapter that handles multiple views. It computes the type of each item (which is small), stores it in a map, initializes it at adapter creation, and updates it in notifyDataSetChanged.
Then you just need to have getViewTypeCount() return the number of possible views. And getItemViewType to return the type from the map (which is 0 based, so 0-getViewTypeCount()). If you can compute your type from the position you don't need the map, but doing this on the fly wasn't possible so I just pre/recompute when needed.