满意答案
xwnb4
2016.09.10
采纳率:49% 等级:10
已帮助:419人
public class ExpertGridAdapter extends BaseAdapter {
private LayoutInflater inflater;
private CsBlogger[] datals;
private Context mContext;
private String TAG="ExpertGridAdapter";
public ExpertGridAdapter(Context context,List childs) {
this.inflater = LayoutInflater.from(context);
datals=new CsBlogger[childs.size()];
childs.toArray(datals);
CsLog.d("maomao", "childs.size:"+childs.size());
mContext=context;
}
@Override
public int getCount() {
return datals.length;
}
@Override
public Object getItem(int position) {
return datals[position];
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView==null) {
holder=new ViewHolder();
convertView=this.inflater.inflate(R.layout.csblog_expert_item_menu, null);
holder.iv=(ImageView) convertView.findViewById(R.id.item_image);
holder.tv=(TextView) convertView.findViewById(R.id.item_text);
convertView.setTag(holder);
}
else {
holder=(ViewHolder) convertView.getTag();
}
CsBlogger expert=datals[position];
DisplayImageOptions options; // 显示图像设置
ImageLoader imageLoader = ImageLoader.getInstance();// 得到图片加载器
// 图片加载器初始化
imageLoader.init(ImageLoaderConfiguration.createDefault(mContext));
// 使用DisplayImageOptions.Builder()创建DisplayImageOptions
options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.blogger) // 设置图片下载期间显示的图片
.showImageForEmptyUri(R.drawable.blogger) // 设置图片Uri为空或是错误的时候显示的图片
.showImageOnFail(R.drawable.blogger) // 设置图片加载或解码过程中发生错误显示的图片
.cacheInMemory() // 设置下载的图片是否缓存在内存中
.cacheOnDisc() // 设置下载的图片是否缓存在SD卡中
.displayer(new RoundedBitmapDisplayer(20)) // 设置成圆角图片
.build(); // 创建配置过得DisplayImageOption对象
// 异步加载图片 专家头像
imageLoader
.displayImage(expert.getUserface(), holder.iv, options);
holder.tv.setText(expert.getNickname());
return convertView;
}
private class ViewHolder{
ImageView iv;
TextView tv;
}
}
00分享举报