serkan stack serkan stack - 4 months ago 34
Android Question

setImage ImageAdapter Android

I downloaded JSON data and converted into POJO Objects successfully. Now, I have a problem that "How can I set image from URL to imagivew attribute of view holder?"

package gc.x;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import gc.ovidos_challenge.R;
import gc.ovidos_challenge.models.Image;

import java.util.List;

public class ImagesAdapter extends RecyclerView.Adapter<ImagesAdapter.MyViewHolder> {

private List<Image> imagesList;

public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView title;
public ImageView imageview;

public MyViewHolder(View view) {
title = (TextView) view.findViewById(;
imageview = (ImageView) view.findViewById(;


public ImagesAdapter(List<Image> imagesList) {
this.imagesList = imagesList;

public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_image, parent, false);

return new MyViewHolder(itemView);

public void onBindViewHolder(MyViewHolder holder, int position) {
Image image = imagesList.get(position);

// holder.imageview.setImage(image.url); //Problem is here, How can I implement?


public int getItemCount() {
return imagesList.size();


I couldn't imagine how to implement setImage method.

Image Class:

public class Image {

public String albumId;
public String id;
public String title;
public String url;
public String thumbnailUrl;



Without using External Library

    new DownloadImageTask(imageview).execute(url);

private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> 
        ImageView bmImage;

        public DownloadImageTask(ImageView bmImage) {
            this.bmImage = bmImage;

        protected Bitmap doInBackground(String... urls) {
            String urldisplay = urls[0];
            Bitmap mIcon11 = null;
            try {
                InputStream in = new;
                mIcon11 = BitmapFactory.decodeStream(in);
            } catch (Exception e) {
                Log.e("Error", e.getMessage());
            return mIcon11;

        protected void onPostExecute(Bitmap result) {

Using Library :

Picasso.with(context).load(image.url).into(//your_image_view );

and compile compile 'com.squareup.picasso:picasso:2.5.2'


Universal Image Loader Lib. Lite Weight.Fast and Easy to use. See this Link