Forum Xamarin.Android

using Switch in ListView Controller

meirrotfleischmeirrotfleisch USMember ✭✭✭
edited June 2020 in Xamarin.Android

Hi

I have a switch as part of the Customcontroller for my list view

I added delegate to it inside the controller but it runs the code on each item on load of the listview

my getView code is

public override View GetView(int position, View convertView, ViewGroup parent)
    {
        View view = convertView;



        if (myEvents[position]!=null)
        {

            if (view == null)
            {
                view = context.LayoutInflater.Inflate(Resource.Layout.EventListItem, null);
                view.FindViewById<TextView>(Resource.Id.eventTitle).Text = myEvents[position].EventName.ToString();
                view.FindViewById<Switch>(Resource.Id.switch4).Checked = myEvents[position].AlarmSet;
                if (myEvents[position].EventDescription != null)
                {
                    view.FindViewById<TextView>(Resource.Id.EventDescription).Text = myEvents[position].EventDescription.ToString();

                }
                view.FindViewById<TextView>(Resource.Id.eventStartDate).Text = myEvents[position].TimeLogged.ToString();
                view.FindViewById < TextView>(Resource.Id.eventId).Text = myEvents[position].id.ToString();
                if (MyUtils.IsOdd(position))
                {
                    view.SetBackgroundColor(Android.Graphics.Color.Azure);
                }
                else
                    {
                    view.SetBackgroundColor(Android.Graphics.Color.BurlyWood);
                }  
            }
        }

        Switch ASwitch = view.FindViewById<Switch>(Resource.Id.switch4);
        ASwitch.Click += delegate
         {
             MyUtils.ChangeAlarm(myEvents[position].id);
         };



        return view;
    }

What do i have wrong here??

Regards

M.R.

Best Answer

Answers

  • meirrotfleischmeirrotfleisch USMember ✭✭✭

    @LandLu Thanks :)

Sign In or Register to comment.