java - Efficient Adapter implementation -
i have in code 2 types adapter implementations , i'm not sure 1 better.
here updater pattern:
public view getview(int position, view convertview, viewgroup parent) { updater content; if(convertview == null) { final textview msg = new textview(parent.getcontext()); content = new updater() { public void update(...) { // code update control msg } }; convertview = msg; convertview.settag(content); } else { content = (updater)convertview.gettag(); } content.update(...); return convertview; } // ... private interface updater { void update(...); }
and here viewholder pattern:
public view getview(int position, view convertview, viewgroup parent) { viewholder holder; if(convertview == null) { convertview = inflater.inflate(...); holder = new viewholder(convertview); convertview.settag(holder); } else { holder = (viewholder)convertview.gettag(); } holder.setdata(...); return convertview; } // ... private class viewholder { public final textview text; public viewholder(final view owner) { text = (textview)owner.findviewbyid(r.id.text); } public void setdata(...) { // ... } }
i'm wondering 1 more effency? implement updater
interface in more complex control, simpler update differnt controls in common way. cast convertview
interface without using gettag()
. in code above use final
variable defined outside of interface implementation. can tell me if can make performance problems? don't know happens internal in java final variable.
if updater pattern bad please tell me, why should use viewholder pattern except pattern google io.
decisions have no effect on performance. both solutions equally efficient. final keyboard may increase performance allowing compiler make optimizations, unoticeable.
Comments
Post a Comment