Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set rating bar to minimum one star?

I have a requirement to rate for a user with minimum of one star and after that ratings should increase to 0.5. But my question is that the user should not change the minimum rating of star to 0.5 or 0. 1 should be the default rating. Please help with this and awaiting for your earlier response. I also tried implementing by listeners from the link but completely struct with the logic inside My code is:

ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {

    @Override public void onRatingChanged(RatingBar ratingBar, float rating, 
      boolean fromUser) {

    }
});
like image 948
Chandru Avatar asked Oct 14 '14 11:10

Chandru


People also ask

How are rating bar ratings set?

A user can simply touch, drag or click on the stars to set the rating value. The value of rating always returns a floating point number which may be 1.0, 2.5, 4.5 etc. In Android, RatingBar is an extension of ProgressBar and SeekBar which shows a rating in stars.

How do I change the rating bar on my android?

Custom Rating Bar in AndroidCopy your images in the drawable folder and remember image size should be according to the size you want. Step 2. Make XML for the rating bar selector in the drawable folder like below. We made two files, one for the fill or highlighted part and one for the empty or un-highlighted part.

How can I give space between star and rating bar in android?

The ratingBar component does not allow to customize spacing between the stars.


2 Answers

 ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {

@Override public void onRatingChanged(RatingBar ratingBar, float rating, 
  boolean fromUser) {
     if(rating<1.0f)
          ratingBar.setRating(1.0f);
}
});
like image 58
Nooh Avatar answered Sep 20 '22 00:09

Nooh


Setting Rating takes float value , in Case ur value is String :

ratingBar.setRating(Float.parseFloat(result));
like image 43
KOTIOS Avatar answered Sep 18 '22 00:09

KOTIOS