Created
December 24, 2017 16:29
-
-
Save prakashpun/c1b6c7f64b9af51926d2fbf3b213d187 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.CustomViewHolder> { | |
private List<RetroPhoto> dataList; | |
private Context context; | |
public CustomAdapter(Context context,List<RetroPhoto> dataList){ | |
this.context = context; | |
this.dataList = dataList; | |
} | |
class CustomViewHolder extends RecyclerView.ViewHolder { | |
public final View mView; | |
TextView txtTitle; | |
private ImageView coverImage; | |
CustomViewHolder(View itemView) { | |
super(itemView); | |
mView = itemView; | |
txtTitle = mView.findViewById(R.id.title); | |
coverImage = mView.findViewById(R.id.coverImage); | |
} | |
} | |
@Override | |
public CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | |
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext()); | |
View view = layoutInflater.inflate(R.layout.custom_row, parent, false); | |
return new CustomViewHolder(view); | |
} | |
@Override | |
public void onBindViewHolder(CustomViewHolder holder, int position) { | |
holder.txtTitle.setText(dataList.get(position).getTitle()); | |
Picasso.Builder builder = new Picasso.Builder(context); | |
builder.downloader(new OkHttp3Downloader(context)); | |
builder.build().load(dataList.get(position).getThumbnailUrl()) | |
.placeholder((R.drawable.ic_launcher_background)) | |
.error(R.drawable.ic_launcher_background) | |
.into(holder.coverImage); | |
} | |
@Override | |
public int getItemCount() { | |
return dataList.size(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment