Rating rounds to fixed stars

1

Good for example:

  

Fill four and a half stars

To set the value I do this:

ratingBar.setRating((float) restaurante.getMedia());

When it comes to information such as 4.5 it rounds up thus putting 5 estrelas ja when I say for example 4.2 it rounds to 4 estrelas I need it to show in case of 4.1 até 4.9 half star

Within my entidade restaurante I have methods GET:SET

private float media;

public float getMedia() {
    return media;
}

public void setMedia(float media) {
    this.media = media;
}

and thus the return:

restaurante.setMedia(Float.valueOf(jRestaurante.getString("media")));
    
asked by anonymous 23.05.2017 / 21:21

1 answer

1

The setRating() method receives a float to be able to consider decimals to partially render the star.

However, in order for it to work, in addition to having to have a decimal value, it is necessary to indicate the granularity (in how the star fill varies with the decimal values) of the rating bar .

Granularity is indicated using the setStepSize () method.

If you want it to be a half-star you should use

ratingBar.setStepSize(0.5);    

If you want the granularity to be at the level of the tenth use

ratingBar.setStepSize(0.1);
    
23.05.2017 / 22:06