What did I do wrong here on my ratingbar?

  • Replies:0
John
  • Forum posts: 1

Oct 26, 2013, 2:43:34 AM via Website

Hope I'm not posting in the wrong place, if I am please let me know. Thank you~

I have two ratingbars and I am using loops to reduce the redundancy but somehow there's a glitch.
I set the app to show the rating value when a user clicks on the rating bar.
E.g.
Ratingbar1 (if two stars are clicked/touched a number 2 will shown)
Ratingbar2 (if four and half stars are clicked/touched a number of 4.5 will shown)

The problem now I'm having is when I clicked two stars on Ratingbar1 then Ratingbar1 will show a number 2 BUT Ratingbar2 will also show 2 and I didn't even touch ratingbar2.
Vise versa, if I clicked 3 stars on ratingbar2 a number 3 beside ratingbar2 and ratingbar1 will show BUT only the number changed the rating on the bar wouldn't change though.

Hopefully the image can explain better than my words.




This is the code I have at the moment.
[code]
//create arrays for the ratingBar
int[] rates = new int[] {R.id.ratingBar1, R.id.ratingBar2};
int r;

for(r = 0; r < rates.length; r++)
{
final int b = r;
RatingBar rb = (RatingBar) findViewById(rates[b]);
rb.setOnRatingBarChangeListener(new OnRatingBarChangeListener()
{
@Override
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
int[] rate_number = new int[] {R.id.rate_number1, R.id.rate_number2};
int rn;
for(rn = 0; rn < rate_number.length; rn++)
{
final int ri = rn;
TextView rate_lotr_number = (TextView)findViewById(rate_number[ri]);
rate_lotr_number.setText(String.valueOf(rating));
}

}
});
}
[/code]

Reply