سؤال

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);
هل كانت مفيدة؟

المحلول

Try this:

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

نصائح أخرى

For your concern you can try ..

int rate = 3.8; // Get your value over here .. 

final RatingBar ratingbar = (RatingBar) rowView.findViewById(R.id.service_rate_bar);
ratingbar.setStepSize((float) 0.25);
ratingbar.setIsIndicator(true);
ratingbar.setRating((int) rate);

and in your xml file define rating bar like this ..

<RatingBar
            android:paddingTop="5dp"
            android:id="@+id/service_rate_bar"
            style="@style/CustomRatingBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:numStars="5"
            android:stepSize="1.0" 

            />
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top