Saturday, April 30, 2011

[android-developers] ViewHolder paradigm vs. using View.setTag()

In the Google I/O 2010 - The world of ListView talk shown here:

http://www.youtube.com/watch?v=wDBM6wVEO70&t=17m38s

a 'ViewHolder' paradigm is suggested to cache views and avoid the
findViewById lookup. Could the same thing be achieved by using the
setTag(id, Object) method on View, and simply use the View's tag map
to store the reference by resource ID? I think this would work, but
would it introduce any memory leak (or other) problems?


public static final View getCachedViewByTagId(View parentView, int
viewToFindId) {
Object object = parentView.getTag(viewToFindId);

if(object == null) {
object = parentView.findViewById(viewToFindId);

if(object != null) {
parentView.setTag(viewToFindId, object);
}
}

return (View)object;
}

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate