@@ -0,0 +1,678 @@
+package com.lwz.android.viewholderadapter;%0A%0Aimport android.util.SparseArray;%0Aimport android.view.View;%0A%0A/**%0A * %E9%80%82%E9%85%8D%E5%99%A8%E4%B8%AD%E7%9A%84 ViewHolder %E7%B1%BB%0A * %0A * @author lwz%0A * @link %E5%8F%82%E8%80%83%EF%BC%9Ahttp://www.piwai.info/android-adapter-good-practices/#Update%0A *%0A */%0Apublic class ViewHolder %7B%0A%09%0A%09@SuppressWarnings(%22unchecked%22)%0A%09public static %3CT extends View%3E T getView(View convertView, int id) %7B%0A%09%09%0A%09%09SparseArray%3CView%3E holder = (SparseArray%3CView%3E) convertView.getTag();%0A%09%09if( holder == null ) %7B%0A%09%09%09holder = new SparseArray%3CView%3E();%0A%09%09%09convertView.setTag(holder);%0A%09%09%7D%0A%09%09%0A%09%09View view = holder.get(id);%0A%09%09if( view == null ) %7B%0A%09%09%09view = convertView.findViewById(id);%0A%09%09%09holder.put(id, view);%0A%09%09%7D%0A%09%09return (T)view;%0A%09%7D%0A%7D%0A

添加 ViewHolder