• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps What did I do wrong here on my ratingbar?

et4891

Lurker
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.

I just realized new user can't post images or links.
Hopefully my explanation isn't hard to understand.
et4891.com/rating.png
the above is where I uploaded an image which I hope full clarify my problem.


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));
                    }
                        
                  }
              });
        }
 
Back
Top Bottom