I always use ViewHolder pattern in my custom ArrayAdapter classes. However, in CursorAdapter the getView() method is not mandatory required to be overridden , but has the bindView and newView methods.
My question is – does CursorAdapter re-uses views by internally implementing the ViewHolder pattern or it needs to be coded as we normally do in custom ArrayAdapter? If it needs to be coded, what is the correct way to do it?
Update
I’m using android.support.v4.widget.CursorAdapter
I’m not sure at what do you refer by the
ViewHolderpattern. If you are referring to having a helper class to cache looking for view each time(and setting it as a tag for the rowView) then the answer is no. If you want to implement this pattern you’ll need to setup the holder(look for the views in the row view withfindViewById) in thenewViewmethod and then set it as the tag for the row view. Then in thebindViewmethod you can callgetTag, retrieve the holder and use it. An example:If you are referring to the
convertViewbeing reused(like in nonCursorbased adapters) then the answer is yes, thegetViewmethod implements this pattern, you just need to implement thenewViewandbindViewmethods and you’re guaranteed to get a view which was recycled(if possible at that moment).