android 如何在listview中使用volley
2014-01-31
展开全部
加载图片?在adapter的getView里面用就好。
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder = null;
if (convertView == null) {
convertView = LayoutInflater.from(mContext).inflate(
R.layout.volley_list_item, null);
viewHolder = new ViewHolder();
viewHolder.mTextView = (TextView) convertView
.findViewById(R.id.tv_tips);
viewHolder.mImageView = (NetworkImageView) convertView
.findViewById(R.id.iv_image);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
String url = "";
url = urlArrays[position % urlArrays.length];
viewHolder.mTextView.setText(position+"|"+urlArrays.length) ;
viewHolder.mImageView.setImageUrl(url, ImageCacheManager.getInstance().getImageLoader());
return convertView;
}
展开全部
private RequestQueue requestQueue;
requestQueue = Volley.newRequestQueue(context);
ImageLoader imageLoader = new ImageLoader(requestQueue,
ImageLruCacheManager.getInstance());//ImageLruCacheManager.getInstance()是自己写的一级缓存
holder.imageView.setDefaultImageResId(R.drawable.defaultcovers);//默认时图片
holder.imageView.setErrorImageResId(R.drawable.defaultcovers);//出错时图片
String url = list.get(position).get("wap_thumb").toString();//获得图片url
holder.imageView.setImageUrl(url, imageLoader);
requestQueue = Volley.newRequestQueue(context);
ImageLoader imageLoader = new ImageLoader(requestQueue,
ImageLruCacheManager.getInstance());//ImageLruCacheManager.getInstance()是自己写的一级缓存
holder.imageView.setDefaultImageResId(R.drawable.defaultcovers);//默认时图片
holder.imageView.setErrorImageResId(R.drawable.defaultcovers);//出错时图片
String url = list.get(position).get("wap_thumb").toString();//获得图片url
holder.imageView.setImageUrl(url, imageLoader);
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询