使用imageload加载图片






public class ListViewAdapter_bianmin_1 extends BaseAdapter {

Context context;
List<User_BianMin_Main> listuser;
public ImageLoader imageLoader;
private LayoutInflater mInflater;
public ListViewAdapter_bianmin_1(Context context){
        this.mInflater = LayoutInflater.from(context);
    }


public ListViewAdapter_bianmin_1(Context context, List<User_BianMin_Main> listuser) {
super();
this.context = context;
this.listuser = listuser;
 ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
           .threadPriority(Thread.NORM_PRIORITY - 2).denyCacheImageMultipleSizesInMemory()
           .diskCacheFileNameGenerator(new Md5FileNameGenerator())
           .tasksProcessingOrder(QueueProcessingType.LIFO).build();
       ImageLoader.getInstance().init(config);
       imageLoader=ImageLoader.getInstance();
}


@Override
public int getCount() {


if (listuser == null) {
return 0;
}


return listuser.size();
}


@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return listuser.get(arg0);
}


@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}


// webviewclient
class myclient extends WebViewClient {


@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
view.loadUrl(url);


return true;
}


}
@Override
public View getView(int arg0, View arg1, ViewGroup arg2) {
// TODO Auto-generated method stub
arg1 = mInflater.from(context).inflate(
R.layout.item_listview_bianmin, null);
ImageView img_bianmin_item_listview = (ImageView) arg1
.findViewById(R.id.img_bianmin_item_listview);
TextView tv_bianmin_title_item_listview = (TextView) arg1
.findViewById(R.id.tv_bianmin_title_item_listview);
TextView tv_bianmin_contex_item_listview = (TextView) arg1
.findViewById(R.id.tv_bianmin_contex_item_listview);
imageLoader.displayImage(listuser.get(arg0).getImage(), img_bianmin_item_listview,getDefaultOptions());
tv_bianmin_title_item_listview.setText(listuser.get(arg0).getTitle());
tv_bianmin_contex_item_listview.setText(listuser.get(arg0).getContent());
return arg1;
}
/**
* 设置默认图片
* @return
*/
public static DisplayImageOptions getDefaultOptions() {
//设置图片加载的属性
        Builder b = new DisplayImageOptions.Builder();
        b.showImageForEmptyUri(R.drawable.no_pic);
        b.showImageOnFail(R.drawable.no_pic);
        b.showImageOnLoading(R.drawable.loading);
        b.resetViewBeforeLoading(Boolean.TRUE);
        b.cacheOnDisk(Boolean.TRUE);
        b.cacheInMemory(Boolean.TRUE);
        b.imageScaleType(ImageScaleType.EXACTLY_STRETCHED);
        return b.bitmapConfig(Bitmap.Config.RGB_565).build();
    }

}

你可能感兴趣的:(使用imageload加载图片)