Back to project page FrameLite.
The source code is released under:
GNU General Public License
If you think the Android project FrameLite listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.miku.framelite.adapter; //w w w . jav a 2s . c om import android.content.Context; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import java.util.ArrayList; import java.util.List; /** * * ??????ViewHolder?Adapter??????<br> * ??????createItemHolder?bindData?createItemView????<br> * * ??:<br> * public class MyHolder extends ViewHolder<br> * {<br> * public TextView itemView;<br> * }<br> * <br> * protected ViewHolder createItemHolder(View convertView)<br> * {<br> * MyHolder holder = new MyHolder();<br> * holder.activityItem = (TextView)convertView.findViewById(R.id.activity_name);<br> * return holder;<br> * }<br> *<br> * protected void bindData(String data,int position, View convertView, ViewGroup parent, ViewHolder h)<br> * {<br> * MyHolder holder = (MyHolder)h;<br> * holder.itemView.setText(data);<br> * }<br> * * public View createItemView(Context context)<br> * {<br> * return View.inflate(context,R.layout.item_view,null);<br> * }<br> * <br> * @author xr.lee * * @param <T> ??????item????????? */ public abstract class FrameBaseAdapter<T> extends BaseAdapter { protected Context mContext; protected List<T> mData = new ArrayList<T>(); protected class ViewHolder { } public FrameBaseAdapter(Context context){ init(context); } public FrameBaseAdapter(Context context, List<T> dataList) { init(context); this.mData = dataList; } private void init(Context context){ mContext = context; } protected abstract ViewHolder createItemHolder(View convertView); protected abstract void bindData(T data,int position, View convertView, ViewGroup parent, ViewHolder holder); public abstract View createItemView(Context context); public void setDataList(List<T> dataList){ this.mData = dataList; this.notifyDataSetChanged(); } public List<T> getDataList(){ return this.mData; } public void clearAllDatas(){ this.mData.clear(); this.notifyDataSetChanged(); } public void addData(T data){ this.mData.add(data); } public void removeData(int position){ this.mData.remove(position); } public void removeData(T data){ this.mData.remove(data); } @Override public int getCount() { int count = mData != null?mData.size():0; return count; } @Override public T getItem(int position) { return mData==null?null:mData.get(position); } @Override public long getItemId(int position) { return position; } @SuppressWarnings("unchecked") @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = null; if (convertView == null ) { convertView = createItemView(mContext); holder = createItemHolder(convertView); convertView.setTag(holder); } holder = (ViewHolder)convertView.getTag(); bindData(getItem(position),position, convertView, parent, holder); return convertView; } }