有没有办法获得复选框的选中状态

Is there away to get a checkbox checked status

我有根据数据库结果由代码创建的复选框。

var checkbox = new CheckBox(this);
var checkBoxes = new CheckBox[0];
//in a for loop I have
checkBox.LayoutParameters = new ViewGroup.LayoutParams(LinearLayout.LayoutParams.WrapContent, LinearLayout.LayoutParams.WrapContent);
line view.AddView(checkBox);
Array.Resize(ref checkBoxes, i + 1);
CheckBoxes[i] = checkBox;

一切正常,我得到了包含数据库中所有名称表的复选框,所以我有 4 个表,我得到了 4 个复选框

问题是我不确定检查是否已选中的最佳方法。 任何帮助将不胜感激

Tried if statement to check if the checkBox.Checked and Al's tried checking if it's TRUE, however seams the if statement has no affect

您是否为复选框的 属性 Checked 分配了值 true

如果您没有这样做,那么 checkBox.Checked 的值将是默认值 false

你可以参考下面的代码,我这边测试过,可以正常使用。

        var layout_main = new LinearLayout(this);
        LinearLayout.LayoutParams p2 = new LinearLayout.LayoutParams(
         LinearLayout.LayoutParams.MatchParent,
        LinearLayout.LayoutParams.WrapContent
        );
        layout_main.LayoutParameters = p2;
        layout_main.Orientation = Orientation.Vertical;

       LinearLayout.LayoutParams param_btn = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.WrapContent);
        param_btn.SetMargins(0,500,0,0);
        var myBtn = new Button(this);
        myBtn.LayoutParameters = param_btn;
        myBtn.Text = "chang text";
        myBtn.Gravity = GravityFlags.Center;

        LinearLayout.LayoutParams param_checkbox = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.WrapContent);
        param_btn.SetMargins(0, 100, 0, 0);
        var checkBox = new CheckBox(this);
        checkBox.LayoutParameters = param_checkbox;
        checkBox.Gravity = GravityFlags.Center;

        checkBox.Text = "test";
        checkBox.Checked = true;



        myBtn.Click += delegate {

            if (checkBox.Checked)
            {
                Toast.MakeText(this, "---> checkBox's checked = " + checkBox.Checked, ToastLength.Long).Show();
            }

        };

        layout_main.AddView(myBtn);

        layout_main.AddView(checkBox);