Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WatchAdapter.java
class WatchAdapter extends RecyclerView.Adapter<WatchAdapter.MyViewHolder> {
private Context context;
private List<Watch> watchList;
class MyViewHolder extends RecyclerView.ViewHolder {
TextView brand, color;
ImageView thumbnail;
MyViewHolder(View view) {
super(view);
brand = (TextView) view.findViewById(R.id.title);
color = (TextView) view.findViewById(R.id.count);
thumbnail = (ImageView) view.findViewById(R.id.thumbnail);
}
}
WatchAdapter(Context mContext, List<Watch> watchList) {
this.context = mContext;
this.watchList = watchList;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.watch_card, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(final MyViewHolder holder, int position) {
Watch watch = watchList.get(position);
holder.brand.setText(watch.getBrand());
holder.color.setText(watch.getColor());
holder.thumbnail.setImageResource(watch.getThumbnail());
}
@Override
public int getItemCount() {
return watchList.size();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment