FlyingPumba / SimpleRatingBar

Open source project which features a simple yet powerful RatingBar alternative to Android's default
Apache License 2.0
1.03k stars 142 forks source link

How to set the max rating? It seems that max rating is always 5 #26

Closed timshinlee closed 7 years ago

timshinlee commented 7 years ago

I love this simple but powerful widget. But I don't know how to change the max rating. Thanks A lot!

FlyingPumba commented 7 years ago

Hi, @timshinlee. Sorry for the late response. If you mean the number of stars, you can change it with app:srb_numberOfStars / setNumberOfStars(int)

timshinlee commented 7 years ago

@FlyingPumba It doesn't matter. Glad to get your response! I mean the max score to determine how many stars to fill in. It seems the max score is always 5. For example, will I be able to call setRating(5f) in the base of 10, then two and a half stars are filled in instead of all?

FlyingPumba commented 7 years ago

@timshinlee Currently there is no method to change the max rating. It's assumed that the max rating is the number of stars. I might add it in the next version (something like setMax in Android's official RatingBar).

Until then, you can of course use rule of Three to convert from one range to the other:

void setRatingBase10(SimpleRatingBar srb, float ratingBase10) {
    srb.setRating(ratingBase10 / 10f * 5f);
}
float getRatingBase10(SimpleRatingBar srb) {
    return srb.getRating() / 5f * 10f;
}
timshinlee commented 7 years ago

@FlyingPumba Cool! I will follow your suggestion. Thanks for your kindly help! Hope this won't bother you.