I have a list of items. These data is received from a API and then listed trough a recycle view. This is how it looks now: https://i.stack.imgur.com/NY34j.jpg
When I press the heart on one of those items, I want to receive the data from that specific item. I'm not sure how do this. Right now I have created a listener to the heart icon, but now I'm stuck. I want to get the data which includes the name, the pictureURL and the expire date.
I have a adapter in which I bind my data with the view. Here is the onCreateViewHolder:
@Override
public FoodViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//inflating and returning our view holder
LayoutInflater inflater = LayoutInflater.from(mCtx);
View view = inflater.inflate(R.layout.layout_food, parent, false);
return new FoodViewHolder(view);
}
This is my OnBindViewHolder-method:
@Override
public void onBindViewHolder(FoodViewHolder holder, int position) {
//getting the product of the specified position
Food food = foodList.get(position);
holder.heart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v){
switch (v.getId()) {
case R.id.heart:
//what code do i write here???
break;
}
}
});
Is this the correct way to do it? Where do I go from here?