Skip to content

Instantly share code, notes, and snippets.

@burnix
Created April 14, 2016 22:43
Show Gist options
  • Save burnix/aa27efe9586213852c108f3d79f3f69d to your computer and use it in GitHub Desktop.
Save burnix/aa27efe9586213852c108f3d79f3f69d to your computer and use it in GitHub Desktop.
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.android.lviv.R;
import com.squareup.picasso.Picasso;
import java.util.List;
/**
* Created by igor on 15.04.16.
*/
public class ImageGridAdapter extends RecyclerView.Adapter<ImageGridAdapter.Holder> {
private Context context;
private List<String> image_urls;
public ImageGridAdapter(Context context, List<String> image_urls) {
this.context = context;
this.image_urls = image_urls;
}
@Override
public ImageGridAdapter.Holder onCreateViewHolder(ViewGroup parent, int viewType) {
return new Holder(LayoutInflater.from(parent.getContext()).inflate(R.layout.image_grid_item, parent, false));
}
@Override
public void onBindViewHolder(Holder holder, int position) {
String url = image_urls.get(position);
System.out.println("url =" + url);
Picasso.with(context)
.load(url)
.into(holder.photo);
}
@Override
public int getItemCount() {
return image_urls.size();
}
public class Holder extends RecyclerView.ViewHolder {
protected ImageView photo;
public Holder(View itemView) {
super(itemView);
photo = (ImageView) itemView.findViewById(R.id.placePhoto);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment