baseadapter 适配器
public class MyAdapter extends BaseAdapter {
Context context;
List<Beans> list;
public MyAdapter(Context context, List<Beans> list) {
// TODO Auto-generated constructor stub
this.context = context;
this.list = list;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return list.get(position);
}
@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
ViewHolder viewHolder = null;
if (convertView == null) {
convertView = View.inflate(context, R.layout.listitem, null);
viewHolder = new ViewHolder();
viewHolder.tv_title = (TextView) convertView
.findViewById(R.id.title);
viewHolder.tv_fast = (TextView) convertView.findViewById(R.id.fast);
viewHolder.img = (ImageView) convertView.findViewById(R.id.img);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.tv_title.setText(list.get(position).toString());
viewHolder.tv_fast.setText(list.get(position).toString());
// 这是Bitmap加载图片
// BitmapUtils utils = new BitmapUtils(context);
// utils.display(viewHolder.img, list.get(position).toString());
// 使用ImageLoader加载图片 创建Application 实现oncreat()方法 ImageLoaderConfiguration configuration = //ImageLoaderConfiguration.createDefault(getApplicationContext());
// ImageLoader.getInstance().init(configuration);
ImageLoader instance = ImageLoader.getInstance();
instance.displayImage(list.get(position).toString(), viewHolder.img);
return convertView;
}
class ViewHolder {
TextView tv_title, tv_fast;
ImageView img;
}
}