Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Checkboxes on listview not checking

$
0
0

Hi

I'm new to Xamarin, this is my first app. Been doing C# for a few years now though. The problem I am having is this. I have an activity with a linear layout, containing two seperate linear layout. In one of the layouts I have a listview

now everything is appearing on the screen as intended, the layout is not the problem. The problem I am having is the checkboxes in the listview cells will not check, the cell turns orange when touched, the ItemClick event is fireing fine, I cannot however get the checkbox to check... if you know what I mean. The cell flashes orange and the visible checkbox just stays unchecked.

The code I am using so far

protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.ch_activate_screen);

        ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
        iPhone.Service1 ipx = new iPhone.Service1();

        DataTable retval = ipx.getRHIVRcut_Android(Intent.GetStringExtra("TRUSTRESID"));

        List<string> names = new List<string>();

        foreach (DataRow row in retval.Rows)
        {
            names.Add(row["name"].ToString());
        }


        DateTime nextdel = new DateTime(2099, 01, 01);
        foreach (DataRow row in retval.Rows)
        {
            if (Convert.ToDateTime(row["dateofdel"]) < nextdel)
            {
                nextdel = Convert.ToDateTime(row["dateofdel"]);
            }
        }


        string[] dates = ipx.getDates(nextdel.Day.ToString(), nextdel.Month.ToString(), nextdel.Year.ToString()).Split('|');

        Spinner spinner = FindViewById<Spinner>(Resource.Id.spinner1);

        ArrayAdapter sss = new ArrayAdapter(this, Android.Resource.Layout.SimpleSpinnerItem, dates);

        ArrayAdapter adapt = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItemMultipleChoice, names);

        ListView list = FindViewById<ListView>(Resource.Id.listView1);

        list.Adapter = adapt;
        spinner.Adapter = sss;

        list.ItemClick += list_ItemClick;

    }


    void list_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
    {
        ListView list = (ListView)sender;

        if (list.IsItemChecked(e.Position))
        {
            list.SetItemChecked(e.Position, false);

        }
        else
        {
            list.SetItemChecked(e.Position, true);
        }

    }

There is a spinner on the page that contains delivery dates, this is working fine, its just the checkboxes in the listview cells. To be honest I wouldn't have thought you would need to do the ItemClicked event, I just put that in to try to set the value of the checkboxes manually. Its still not working though.

Any ideas would be greatly appreciated!

Thanks

Steve.


Viewing all articles
Browse latest Browse all 204402

Trending Articles