参考:http://blog.csdn.net/hellogv/article/details/6541286
package mobi.develop.adapter;
import java.util.ArrayList;
import java.util.List;
import mobi.develop.view.ImageTextHView;
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import com.androidTT.data.Cache;
/**
* ListView 的 Adapter
* **/
public class ListViewAdapter extends BaseAdapter{
private Activity mContext;
private List<Integer> lstPosition=new ArrayList<Integer>();
private List<View> lstView=new ArrayList<View>();
public ListViewAdapter(Activity context){
mContext = context;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return Cache.imgPathArrayList.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if (lstPosition.contains(position) == false) {
if(lstPosition.size()>20){//这里设置缓存的Item数量
lstPosition.remove(0);//删除第一项
lstView.remove(0);//删除第一项
}
ImageTextHView imageTextHView = new ImageTextHView(mContext,position);
convertView = imageTextHView;
lstPosition.add(position);//添加最新项
lstView.add(convertView);//添加最新项
}else{
convertView = lstView.get(lstPosition.indexOf(position));
}
return convertView;
}
}