Adapter 数据缓存

参考: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;

}

}

posted @ 2011-12-21 11:37  镇水古月  阅读(243)  评论(0编辑  收藏  举报