Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save khaledMohammed000/f18385f9d9b5fab9117c6790710e7e7c to your computer and use it in GitHub Desktop.

Select an option

Save khaledMohammed000/f18385f9d9b5fab9117c6790710e7e7c to your computer and use it in GitHub Desktop.
Small bit of code for using Picasso inour getView() in Adapter class
public class MoviesAdapter extends BaseAdapter {
private Context mContext;
private MoviesModel mArray[];
String posterPathReturnedByQuery = null;
String finalImageURL = null;
final public String BaseImageURL = "http://image.tmdb.org/t/p/";
final public String StandardSIzeOfImages = "w185";
// Constructor
public MoviesAdapter(Context c,MoviesModel array[]) {
mContext = c;
mArray = array;
}
@Override
public int getCount() {
return mArray.length;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
// if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
} else {
imageView = (ImageView) convertView;
}
// http://image.tmdb.org/t/p/w185//nBNZadXqJSdt05SHLqgT0HuC5Gm.jpg
posterPathReturnedByQuery = mArray[position].getPoster_path();
finalImageURL = BaseImageURL + StandardSIzeOfImages + posterPathReturnedByQuery;
Picasso
.with(mContext)
.load(finalImageURL)
.resize(600,800)
.into(imageView);
//imageView.setImageResource(mThumbIds[position]);
return imageView;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment