上一篇博客写了单张的读取这一篇写一下结合lisetview 的多图加载
结合list其实也就是结合adapter 实现;这里是adapter代码关于其他的代码请参照
http://blog.csdn.net/u012373815/article/details/47619457
标红的是需要注意的地方
publicclassListAdapter extends BaseAdapter {
private LayoutInflatermyIntflater;
private List<Rubbish>rulist;
private ImageViewthingmage ;
private ImageLoaderimageLoader;
//这里是我默认定义的一些图片。当这个物品在服务器上没有上传图片那么就默认使用该物品所在类别的类别图片,这个是类别的图片集合
privateint[] imageid =new int[] {
R.drawable.feizhi, R.drawable.suliao,
R.drawable.jiaju, R.drawable.jinshu, R.drawable.boli,
R.drawable.buliao, R.drawable.dianqi, R.drawable.all,
R.drawable.qidai };
Imageleibeileibieimages=newImageleibei();
//在这里要对imageLoader进行实例化它是单例模式
//List<Rubbish> list 是我的数据集,是我需要显示的数据
publicListAdapter(Context c, List<Rubbish>list) {
myIntflater = LayoutInflater.from(c);
this.rulist = list;
imageLoader=newImageLoader(c);
}
@Override
publicint getCount() {
//TODO Auto-generated method stub
returnrulist.size();
}
@Override
public Object getItem(int position) {
//TODO Auto-generated method stub
returnrulist.get(position);
}
//得到当前Items的position
@Override
publiclong getItemId(int position) {
//TODO Auto-generated method stub
return position;
}
@SuppressLint({"ViewHolder","InflateParams" })
@Override
public View getView(int position, ViewconvertView, ViewGroup parent) {
//讲数据填充到list_item,中
convertView= myIntflater.inflate(R.layout.list_item,null);
//使相邻两条数据的背景颜色不一样,便于美观
if (position % 2 == 0) {
convertView.setBackgroundColor(Color.WHITE);
}
//初始化list_item中的控件
thingmage = (ImageView)convertView
.findViewById(R.id.leibieimage);
TextViewtxtthingname = (TextView) convertView.findViewById(R.id.txtthingname);
TextViewtxtfreetime = (TextView) convertView
.findViewById(R.id.txtfreetime);
TextViewtxtfabutime = (TextView) convertView
.findViewById(R.id.txtfabutime);
//将数据适配到控件中去 txtthingname.setText(rulist.get(position).getThingname().toString());
txtfabutime.setText(rulist.get(position).getThingfabutime().toString());
txtfreetime.setText(rulist.get(position).getThingfreetime().toString());
//引入图像
Stringimgurl = rulist.get(position).getThingimg().toString();
Stringleibie = rulist.get(position).getThingleibie().toString();
//thingmage.setImageResource(imageid[leibieimages.leibieImage(leibie)]);
if (imgurl.equals("")) {//网络无图片这时加载该物品类别的图片
thingmage.setImageResource(imageid[leibieimages.leibieImage(leibie)]);
}else{
// 有图片读取网络图片
//imgurl="http://192.168.1.104:8080"+imgurl;
//HttpPath.ALLIMAGEPATH(imgurl)网络图片地址的拼接
System.out.println(imgurl+"0000000000");
imageLoader.DisplayImage(HttpPath.ALLIMAGEPATH(imgurl),thingmage);
}
return convertView;
}
}
衣服显示的图片为本地的物品类别图片。水杯电脑手机显示的图片为从网络加载的