Forum Xamarin.Android

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Not able to get correct viewholder value in ListView to update text value depending on seekbar

Hello Forum,

I have implemented viewholder pattern for custom adapter to populate listview, which is working good.

Now I have seekbar in each row and wish to show the current progress value textview adjacent to it, but now when i change any seekbar then last row textview value get updated instead of its adjacent.

Below is my code, please assist to let me know what wrong I am doing.

public class ScoreCardAdapter : BaseAdapter<scorecardlist>
        {

            private readonly IList<scorecardlist> _items;
            private readonly Context _context;
            viewHolder viewholder;

            public static List<string> ScoreCardAdapter_Floor = new List<string>();


            private class viewHolder : Java.Lang.Object
            {
                public int pk { get; set; }

                public TextView tv_scorecardText { get; set; }
                public TextView tv_scorecardScore { get; set; }
                public SeekBar sc_scorecardToggleButton { get; set; }
            }

            public ScoreCardAdapter(Context context, IList<scorecardlist> items)
            {
                _items = items;
                _context = context;
            }

            public override int Count
            {
                get { return _items.Count; }
            }

            public override scorecardlist this[int position]
            {
                get { return _items[position]; }
            }

            public override long GetItemId(int position)
            {
                return position;
            }

            public override View GetView(int position, View convertView, ViewGroup parent)
            {
                var item = _items[position];
                var view = convertView;



                if (view == null)
                {
                    var inflater = LayoutInflater.FromContext(_context);
                    view = inflater.Inflate(Resource.Layout.ListView_Scorecard, parent, false);

                    viewholder = new viewHolder();



                    viewholder.pk = item.pk;
                    viewholder.tv_scorecardScore = view.FindViewById<TextView>(Resource.Id.scorecardMarks);
                    viewholder.tv_scorecardText = view.FindViewById<TextView>(Resource.Id.scorecardText);
                    viewholder.sc_scorecardToggleButton = view.FindViewById<SeekBar>(Resource.Id.scorecardToggleButton);


                    //viewholder.tv_scorecardScore.SetTag(item.pk, "");
                    //viewholder.sc_scorecardToggleButton.SetTag(item.pk, "");

                    if (item.pk == 0)
                    {
                        viewholder.sc_scorecardToggleButton.Enabled = false;                        
                        viewholder.tv_scorecardText.SetTextColor(Android.Graphics.Color.Gray);
                        viewholder.tv_scorecardScore.SetTextColor(Android.Graphics.Color.Gray);
                    }
                    else
                    {
                        viewholder.sc_scorecardToggleButton.ProgressChanged += delegate (object sender, SeekBar.ProgressChangedEventArgs e)
                        {
                            if (e.Progress <= 0)
                            {
                                //checkDonePkInList(ScoreCardAdapter.ScoreCardAdapter_Floor, item.pk.ToString(), "Not Done");
                                string srt = item.pk.ToString();
                                viewholder.tv_scorecardScore.Text = e.Progress.ToString();
                            }
                            else
                            {
                                string srt = item.pk.ToString();
                                //checkDonePkInList(ScoreCardAdapter.ScoreCardAdapter_Floor, item.pk.ToString(), "Done");

                                viewholder.tv_scorecardScore.Text = e.Progress.ToString();
                            }
                        };
                    }
                    view.Tag = viewholder;                    
                }
                else
                {
                    viewholder = view.Tag as viewHolder;
                }
                viewholder.tv_scorecardScore.Text = item.score;
                viewholder.tv_scorecardText.Text = item.paramentName;
                viewholder.pk = item.pk;

                return view;

            }    

        } 

Thank you,
Sandip Kumbhar.

Sign In or Register to comment.