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

Get Checked from Checkbox in ListViewItem out of ListViewActivity

$
0
0

Hi everyone,

i already tried everything i could think of, but i'm still stuck.

My Problem: I have an Activity that starts another Activity (lets call it "SelectActivity") with a ListView. This SelectActivity has an Adapter for the ListView. I would like to return all tags from selected Checkboxes.

But i can't get the tags, 'cause it will keep return "null" if i try to find them with FindViewById.

I could really need a little help.

OnCreate in "SelectActivity" looks as following: ` List checkedContacts = new List();

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

        var contactsAdapter = new ContactsAdapter (this);
        var contactsListView = FindViewById<ListView> (Resource.Id.ContactsListView);
        contactsListView.Adapter = contactsAdapter;

        var checkbox = contactsListView.FindViewById<CheckBox> (Resource.Id.ContactCheckbox);
        checkbox.Click += (o, e) => {
            var cb = (CheckBox)o;
            var item = (int)cb.Tag;

            if(checkedContacts.Any(it => it == item))
            {
                if(!cb.Checked)
                {
                    checkedContacts.Remove(item);
                }
            } else {
                if(cb.Checked)
                {
                    checkedContacts.Add(item);
                }
            }
        };
    }`

I would really appreciate any kind of help.


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>