Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rasoulmiri
Created September 18, 2017 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rasoulmiri/8fa21cac954a6b2787fc1889e5649d39 to your computer and use it in GitHub Desktop.
Save rasoulmiri/8fa21cac954a6b2787fc1889e5649d39 to your computer and use it in GitHub Desktop.
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