1

我正在尝试通过适配器将图像通过 URL 加载到我的 ListView,但 AQuery 似乎没有将 URL 加载到 ImageViews。我曾尝试使用 Picasso Image Loader 执行此操作,但它确实有效,但我更喜欢 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 中正确加载“名称”字段,但在 ImageView 中留下空白。我究竟做错了什么?

4

2 回答 2

1

使用毕加索为Android图像下载和缓存库

于 2015-05-18T18:21:56.127 回答
1

首先你需要有像本教程这样的静态类

在 ViewHolder 类中添加 String url;

比在 getView 上添加这个来加载

if (viewHolder.url == null || url.equals(viewHolder.url)){
  viewHolder.url = url;
  // load image 
}
于 2015-05-19T04:02:18.640 回答