You need to use add the OnRatingBarChangeListener
to handle the OnRatingBarChanged
event.
Add the necesary code to the onBindViewHolder
method:
@Override
public void onBindViewHolder(@NonNull FoodViewHolder foodViewHolder, int i) {
FoodItem currentItem = arrayList.get(i);
foodViewHolder.viewHolderImageView.setImageResource(currentItem.getFoodImage());
foodViewHolder.viewHolderTextView.setText(currentItem.getFoodName());
foodViewHolder.viewHolderRatigBar.setRating(currentItem.getFoodRating());
foodViewHolder.viewHolderRatigBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener(){
@Override
public void onRatingBarChanged(RatingBar ratingBar, float rating, boolean fromUser){
currentItem.setFoodRating(rating);
}
}
}
NOTE:
The value “rating” passed to the onRatingBarChanged()
method is of type float
so you will need to change your FoodItem
class to accommodate this type.
If you wish to persist this value you will need to include some mechanism to save the new rating value–perhaps in a database.
0
solved How to make a RecyclerView with a ratngBar inside it so the the user can rate the RecylerView items