我正在尝试通过URL通过适配器将图像加载到我的ListView,但是AQuery似乎没有将URL加载到ImageViews。我试着用毕加索的图像装载机做这件事,它成功了,但我更喜欢AQuery,我需要解决这个问题。我在用安卓工作室。
public class FeedAdapter extends ArrayAdapter<ActivityTable> {
ArrayList<ActivityTable> activities = new ArrayList<ActivityTable>();
Context ctx;
int resource;
AQuery aq;
public FeedAdapter(Context context, int resource, ArrayList<ActivityTable> activityList) {
super(context, resource, activityList);
this.activities = activityList;
this.ctx = context;
this.resource = resource;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi;
vi = LayoutInflater.from(getContext());
v = vi.inflate(R.layout.newsfeed_single, null);
}
ActivityTable p = new ActivityTable(); //Object of type ActivityTable
for(ActivityTable item: activities) {
p = activities.get(position);
}
if (p != null) {
TextView owner_text = (TextView) v.findViewById(R.id.post_owner);
ImageView post_picture = (ImageView) v.findViewById(R.id.post_media);
owner_text.setText(p.getUser().getFname());
AQuery aq = new AQuery(ctx);
aq.id(R.id.post_media).image(p.getURL()); //getURL() Returns the Image URL
//The URL is valid and I checked whether it works through Picasso Image Loader
}
return v;
}
}应用程序在ListView中正确地加载“name”字段,但在ImageView中留下一个空白。我做错了什么?
发布于 2015-05-18 18:21:56
使用毕加索为Android提供图像下载和缓存库
发布于 2015-05-19 04:02:18
首先,您需要像这个教程那样的静态类
在ViewHolder类中添加字符串url;
而不是在getView上将此添加到加载中
if (viewHolder.url == null || url.equals(viewHolder.url)){
viewHolder.url = url;
// load image
}https://stackoverflow.com/questions/30309839
复制相似问题