WatchAdapter.java
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
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