AQuery不会在Android Studio中加载图像

时间:2015-05-18 17:51:58

标签: android android-activity listview-adapter aquery

我正在尝试通过适配器将图像通过URL加载到我的ListView,但AQuery似乎没有将URL加载到ImageViews。我试过用Picasso Image Loader做这个,但是我很喜欢AQuery,我需要解决这个问题。我正在使用Android Studio。

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中留下空白。我做错了什么?

2 个答案:

答案 0 :(得分:1)

使用picasso映像Android的下载和缓存库

答案 1 :(得分:1)

首先你需要有静态类 像这样tutorial

在ViewHolder类中添加String url;

而不是在getView上加载它

php