Picasso Library and GridView Images

I want to create an application that displays images in a gridview using the picasso library. Images are retrieved by the remote server. Should I create an AsyncTask class or is this class handled by the Picasso library itself? All the Picasso lessons I've seen so far seem a bit vague.

Thanks,

Theo.

+5
source share
1 answer

Its very simple to use picasso lib to upload images to gridview, as shown here ,

class SampleGridViewAdapter extends BaseAdapter { private final Context context; private final List<String> urls = new ArrayList<String>(); public SampleGridViewAdapter(Context context) { this.context = context; // Ensure we get a different ordering of images on each run. Collections.addAll(urls, Data.URLS); Collections.shuffle(urls); // Triple up the list. ArrayList<String> copy = new ArrayList<String>(urls); urls.addAll(copy); urls.addAll(copy); } @Override public View getView(int position, View convertView, ViewGroup parent) { SquaredImageView view = (SquaredImageView) convertView; if (view == null) { view = new SquaredImageView(context); view.setScaleType(CENTER_CROP); } // Get the image URL for the current position. String url = getItem(position); // Trigger the download of the URL asynchronously into the image view. Picasso.with(context) // .load(url) // .placeholder(R.drawable.placeholder) // .error(R.drawable.error) // .fit() // .tag(context) // .into(view); return view; } @Override public int getCount() { return urls.size(); } @Override public String getItem(int position) { return urls.get(position); } @Override public long getItemId(int position) { return position; } } 
+7
source

All Articles