I am having some problem when trying to highlight the ratingBar star based on the data returned from database. So basically I have this ratingBar:
ratingBar = (RatingBar) eventChat.findViewById(R.id.ratingBar);
And then I perform a check for the rates return from database, if not null then I wanted to set the highlighted star based on the integer:
if (reviewModel.getEventReviewRate() != null) {
existStarRate = Integer.parseInt(reviewModel.getEventReviewRate());
Log.i("existStarRate", String.valueOf(existStarRate));
}
if (existStarRate <= 0) {
LayerDrawable stars = (LayerDrawable) ratingBar
.getProgressDrawable();
stars.getDrawable(2).setColorFilter(
(context.getResources().getColor(R.color.lightred)),
PorterDuff.Mode.SRC_ATOP);
ratingBar.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View view, MotionEvent event) {
return true;
}
});
}
I customize the highlighted star by these codes:
LayerDrawable stars = (LayerDrawable) ratingBar
.getProgressDrawable();
stars.getDrawable(2).setColorFilter(
(context.getResources().getColor(R.color.lightred)),
PorterDuff.Mode.SRC_ATOP);
However, I have no idea how to set the highlighted star dynamically. Let's say currently the data returned from database is 4, I should set 4 of my ratingBar star to be highlighted in lightred color.
Any ideas?
Thanks in advance.