Search code examples
javaandroidratingbar

How to make stars in a Android ratingBar display double values?


In my code, the RatingBar shows the nearest double number. For example, if I have the value of 3.5, it shows it as 4 stars and if I have 3.2, it shows it as 3 stars. It always makes it to the nearest round number integer value.

The code I used:

TextView rateavg =(TextView)findViewById(R.id.textView1);
rateavg.setText(stringrate);
RatingBar ratingBar = (RatingBar)findViewById(R.id.ratingBar1);
ratingBar.setEnabled(false);
ratingBar.setMax(5); // I assume 5 is your max rating
ratingBar.setRating(Float.parseFloat(stringrate));
ratingBar.setStepSize(0.5f);

Solution

  • Try this:

    ratingBar.setEnabled(false);
    ratingBar.setMax(5);
    ratingBar.setStepSize(0.01f);
    ratingBar.setRating(Float.parseFloat(stringrate));
    ratingBar.invalidate();