Adarsh
Adarsh

Reputation: 125

Set value retrieved from database as string to rating bar in android

I need to set value retrieved from mysql database (as string) as rating value. I have successfully retrieved the database value to a string . But I don't know how to set this value to rating bar. (for example, if database value that I retrieve in the string is 3, then the rating bar's first 3 stars should indicate that with color change), Please help me with a good support.Thanks in advance!

Upvotes: 0

Views: 1349

Answers (2)

anirban karak
anirban karak

Reputation: 740

String yourStringValueFromDatabase = "2"; // you need to read it from sqlite

float ratingBarObq= Float.parseFloat(yourStringValueFromDatabase );

ratingBarObq.setRating(ratingValue); //Sets the rating(the number of stars filled).

int numratingStars = Integer.parseInt(somedbvalue); ratingBarObq.setNumStars(numratingStars);//Sets the number of stars to show.

Upvotes: 0

fractalwrench
fractalwrench

Reputation: 4076

RatingBar allows you to set the number of displayed stars via its API. Something like below would show you three stars:

String yourString = "3"; // TODO read from DB
float rating = Float.parseFloat(yourString);
ratingBar.setRating(rating);

Upvotes: 1

Related Questions