1

I'm trying to load images through a URL to my ListView through an adapter but AQuery doesn't seem to load the URLs to the ImageViews. I have tried doing this with Picasso Image Loader and it worked but I prefer AQuery and I need to resolve this issue. I'm using 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;

    }
}

The application loads the 'name' fields properly in the ListView but leaves a blank in the ImageView. What am I doing wrong?

Jay
  • 4,873
  • 7
  • 72
  • 137
  • Did you solve this ? I'm having a similar issue migrating an app from eclipse, where aquery seems to work just fine. – SQLiteNoob Aug 15 '15 at 14:13

2 Answers2

1

use picasso to image downloading and caching library for Android

  • I did. But there's a bunch of weird issue sin it. The images load however when I scroll to the bottom of the listview and go up, some images disappear o.O – Jay May 18 '15 at 18:30
  • add image Url to your static class "ViewHolder" and if (url == null || url.equals(viewHolder.url)){ viewHolder.url = url; // load image } – Adham Goussous May 18 '15 at 18:35
  • I didn't get that. Can you please post it as an answer? – Jay May 19 '15 at 00:43
1

first you need to have static class like this tutorial

in ViewHolder class add String url;

than on getView add this to load

if (viewHolder.url == null || url.equals(viewHolder.url)){
  viewHolder.url = url;
  // load image 
}