Rating bar in recyclerview showing strange results on rating change

HabelPhilipHabelPhilip USMember
edited December 2015 in Xamarin.Android

While using more than 9 rating bars in a recyclerview,its showing strange values. ie; when i rate a rating bar other rating bar also changes its value.
Here is my code

   public class SurveyAdapter : RecyclerView.Adapter
    {
        const String TAG = "QUICK_ADAPTER";

        public override RecyclerView.ViewHolder OnCreateViewHolder (ViewGroup parent, int viewType)
        { 
            View v = LayoutInflater.From (parent.Context).Inflate (Resource.Layout.survey_items, parent, false); 
            return new ViewHolder (v);
        }

        public override void OnBindViewHolder (RecyclerView.ViewHolder holder, int position)
        {
            var vh = holder as ViewHolder;  

            vh.ratingBar.Rating = 0;
            vh.ratingBar.RatingBarChange += (o, e) => { 
                Log.Error (TAG, "Rating change pos:" + position + "  & value :" + (int)vh.ratingBar.Rating + "\n");
            }; 
        }

        public override int ItemCount {
            get { return 20; }
        }

        public class ViewHolder : RecyclerView.ViewHolder
        {
            public    RatingBar ratingBar{ get; private set; }

            public ViewHolder (View itemView) : base (itemView)
            {
                itemView.FindViewById<RatingBar> (Resource.Id.Rating);
            }
        }
    }

I am getting results like this when changing rating in a ratingbar.
suppose i rate ratingbar at position 1
Rating change pos:1 & value: 4
Rating change pos:8 & value: 4
Rating change pos:12 & value: 4
Rating change pos:14 & value: 4

Sign In or Register to comment.