Doubt when validating CheckBox that dynamically creates

0

I have a project in Xamarin and through this code, dynamically generate more than one CheckBox

if (Lista != null && Lista.Count > 0)
{
    LayoutParams lp = new LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent);

    foreach (var f in Lista)
    {
        CheckBox chProducto = new CheckBox(this);
        chProducto.Text = f.Concepto + " - $ " + f.Importe.ToString();
        chProducto.CheckedChange += chProducto_Checked;

        linLayBody.AddView(chProducto, lp);
    }
}

That is to say that given a list, I am creating a CheckBox (chProduct) for each element of the list, but then I want to validate which were the CheckBox that were "marked" and I got stuck because I did not know how to continue since the quantity of CheckBox that you are going to add is never fixed ... at some point they can be 2 and at another moment they can be 10 ...

Could someone help me continue?

Thanks in advance!

    
asked by Matias 04.04.2017 в 15:42
source

2 answers

1

The easiest way to do this (which is not the only one) is to have a list (or a collection, or an array, or whatever you find simpler) that saves the objects you are adding to the view (this is to avoid going through the view).

Then you would have the objects in the view and also in your array. Then the only thing you have to do is go through that array and check what you need from each one.

    
answered by 04.04.2017 / 15:44
source
0

I recommend that you create a clickbox check event and that you add it dynamically to each checkbox that you create. Create also a checkbox list (lCheck) in the click event, you have the checkbox in which you clicked added to the checkpoint Then you go through the Check filter by Check = true and you will have all the checks marked

    
answered by 04.04.2017 в 16:10