@@ -0,0 +1,1317 @@
+package com.lwz.android.viewholderadapter;%0A%0Aimport java.util.List;%0A%0Aimport android.content.Context;%0Aimport android.view.View;%0Aimport android.view.ViewGroup;%0Aimport android.widget.BaseAdapter;%0A%0A/**%0A * ViewHodler %E9%80%82%E9%85%8D%E5%99%A8%0A * %3Cp%3E%0A * %E8%AF%A5%E9%80%82%E9%85%8D%E5%99%A8%E6%98%AF%E9%80%9A%E8%BF%87%E6%B5%81%E8%A1%8C%E7%9A%84 ViewHolder %E6%9D%A5%E4%BC%98%E5%8C%96 AdapterView %E7%9A%84%E6%80%A7%E8%83%BD%E3%80%82%E8%AF%A5%E9%80%82%E9%85%8D%E5%99%A8%E4%BD%BF%E5%BE%97%E4%BD%BF%E7%94%A8%E8%80%85%E5%8F%AA%E5%85%B3%E5%BF%83%E6%95%B0%E6%8D%AE%E7%BB%91%E5%AE%9A%E9%83%A8%E5%88%86%E8%80%8C%E4%B8%8D%E7%94%A8%E5%8E%BB%E5%85%B3%E5%BF%83%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0%0A * %3C/p%3E%0A * @author lwz%0A *%0A * @param %3CT%3E List %E4%B8%AD%E7%9A%84%E7%B1%BB%E5%9E%8B%0A */%0Apublic abstract class ViewHolderAdapter%3CT%3E extends BaseAdapter %7B%0A%09%0A%09private Context mContext;%0A%09private List%3CT%3E mData;%0A%09private int mLayoutRes;%0A%09%0A%09public ViewHolderAdapter(Context context, List%3CT%3E data, int layoutRes) %7B%0A%09%09mContext = context;%0A%09%09mData = data;%0A%09%09mLayoutRes = layoutRes;%0A%09%7D%0A%0A%09@Override%0A%09public int getCount() %7B%0A%09%09return mData.size();%0A%09%7D%0A%0A%09@Override%0A%09public T getItem(int position) %7B%0A%09%09return mData.get(position);%0A%09%7D%0A%0A%09@Override%0A%09public long getItemId(int position) %7B%0A%09%09return position;%0A%09%7D%0A%0A%09@Override%0A%09public View getView(int position, View convertView, ViewGroup parent) %7B%0A%09%09if( convertView == null ) %7B%0A%09%09%09convertView = View.inflate(mContext, mLayoutRes, null);%0A%09%09%7D%0A%09%09%0A%09%09bindData(position, convertView, getItem(position));%0A%09%09%0A%09%09return convertView;%0A%09%7D%0A%09%0A%09abstract protected void bindData(int pos, View convertView, T itemData);%0A%0A%09public %3CK extends View%3E K getViewFromHolder( View convertView, int id ) %7B%0A%09%09return ViewHolder.getView(convertView, id);%0A%09%7D%0A%7D%0A

添加基于 ViewHolder 的适配器