基类适配器Adapter

由于适配器的封装的写法太多,这边我就直接上代码了。

public abstract class CommonAdapter extends BaseAdapter{

protected Context mContext;
protected List mData;
protected int mLayoutId;

public CommonAdapter(Context context,List data,int layoutId){
    mContext = context;
    mData = data;
    mLayoutId = layoutId;
}

@Override
public int getCount() {
    return mData.size();
}

@Override
public T getItem(int i) {
    return mData.get(i);
}

@Override
public long getItemId(int i) {
    return i;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder = ViewHolder.getHolder(mContext,convertView,mLayoutId,parent,position);
    convert(holder,position);
    return holder.getConvertView();
}

/**
 * get holder convert
 */
public abstract void convert(ViewHolder holder,int position);

}

你可能感兴趣的:(基类适配器Adapter)