Closed Mina-Mikhail closed 6 years ago
Hello @Mina-Mikhail,
You need to handle the onRatingChange
event to update your list(arrayDetails) value,
for example:
holder.ratingBar.setOnRatingChangeListener(new BaseRatingBar.OnRatingChangeListener() {
@Override
public void onRatingChange(BaseRatingBar ratingBar, float rating) {
list.remove(holder.getAdapterPosition());
list.add(holder.getAdapterPosition(), (int) rating);
}
});
if still can't solve this problem, please let me know, thanks!
Hello @ome450901
I think i didn't need to implement onRatingChange
, because i use rating bar to show rate amount only, and it not Clickable ?? why use onRatingChange
This is the case, i use the library to display amount of rate only, the first comment have 1 star and second have 3 stars, when i scroll down to see other comments and back again to top , the stars was cleared. and first , second other comments have no stars (not rated) !!
Sorry, I misunderstood the problem.
I find out the problem is holder.placeRateAmount.setNumStars(5);
because it will remove all views and regenerate it, so the rating will be cleared.
seems your Num of Stars won't change at all, so I think you should set this value in XML not in the onBindViewHolder
.
just modify your xml to the following code and remove holder.placeRateAmount.setNumStars(5);
:
<com.willy.ratingbar.ScaleRatingBar
android:id="@+id/place_rate_amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srb_clickable="false"
app:srb_drawableEmpty="@drawable/ic_not_rated"
app:srb_drawableFilled="@drawable/ic_top_rated"
app:srb_isIndicator="true"
app:srb_scrollable="false"
app:srb_starHeight="15dp"
app:srb_starPadding="3dp"
app:srb_starWidth="15dp"
app:srb_stepSize="1"
app:srb_clearRatingEnabled="false"
app:srb_numStars="5"
/>
I have an issue when use this library inside recyclerView.
This is my item: `<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?android:selectableItemBackground" android:clickable="true" android:focusable="true" android:orientation="horizontal" android:padding="16dp"
<View android:layout_width="match_parent" android:layout_height="1dp" android:alpha="0.4" android:background="@color/gray" />
`
and this is my adapter: `public void onBindViewHolder(CustomViewHolder holder, int i) { holder.placeRateAmount.setNumStars(5); holder.placeRateAmount.setRating(arrayDetails.get(i).getRate());
}`
When scroll on recyclerView and return back to item 1, the rating bar was cleared !! how to solve this issue ?!!