Round rating for fixed stars

Asked

Viewed 112 times

1

Good precise for example:

Fill 4 and a half stars

To set the value I do so:

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

When information comes from for example 4.5 he rounds up putting like this 5 estrelas when I’m already in charge for example 4.2 he rounds to 4 estrelas I need you to show me in case 4.1 até 4.9 half star

Inside my entidade restaurante have the methods GET:SET

private float media;

public float getMedia() {
    return media;
}

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

and so the return:

restaurante.setMedia(Float.valueOf(jRestaurante.getString("media")));
  • Tried using Float.parseFloat?

  • No, I’ll try here and tell you

  • @Nayronmorais so in case ? ratingBar.setRating(Float.parseFloat(String.valueOf(restaurant.getMedia())));

  • If it’s like this, it didn’t work

1 answer

1


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

However, for it to work, it is not only necessary that the value it receives has decimals, it is necessary to indicate the granularity (how the star’s fill varies with the decimals of the value) of the rating bar.

Granularity is indicated using the method setStepSize().

If you want her to be half a star you should wear

ratingBar.setStepSize(0.5);    

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

ratingBar.setStepSize(0.1);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.