如何使用imageloader加载图片

//配置类

package com.example.imageloader;


import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;


import android.app.Application;


public class ImageApplication extends Application {



@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();

//初始化ImageLoader
ImageLoaderConfiguration configuration=ImageLoaderConfiguration.createDefault(this);
ImageLoader.getInstance().init(configuration);

}
}

//适配器中的使用

package com.example.adapter;


import java.util.List;


import com.example.imageloader.R;
import com.example.vo.Books;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


public class MyListAdapter extends BaseAdapter {
Context applicationContext;
List<Books> list_books;




public MyListAdapter(Context applicationContext, List<Books> list_books) {
super();
this.applicationContext = applicationContext;
this.list_books = list_books;
}


@Override
public int getCount() {
// TODO Auto-generated method stub
return list_books.size();
}


@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return list_books.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) {
ViewHolder v=null;
if (convertView==null) {
v=new ViewHolder();
convertView=LayoutInflater.from(applicationContext).inflate(R.layout.listinfo_item, null);
v.title=(TextView) convertView.findViewById(R.id.title);
v.iv=(ImageView) convertView.findViewById(R.id.image);
v.catadog=(TextView) convertView.findViewById(R.id.catalog);
v.read=(TextView) convertView.findViewById(R.id.reading);
v.time=(TextView) convertView.findViewById(R.id.bytime);
convertView.setTag(v);
}else{
v=(ViewHolder) convertView.getTag();
}
v.title.setText(list_books.get(position).getTitle());
v.catadog.setText(list_books.get(position).getCatalog());
v.read.setText(list_books.get(position).getReading());
v.time.setText(list_books.get(position).getBytime());

DisplayImageOptions options=new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisc(true).build();

ImageLoader.getInstance().displayImage(list_books.get(position).getImg(), v.iv, options);


return convertView;
}


class ViewHolder{
TextView title,catadog,read,time;
ImageView iv;
}
}


你可能感兴趣的:(ImageLoader)