gpt4 book ai didi

c# - 选中/取消选中 TableLayout 中的多个复选框

转载 作者:太空宇宙 更新时间:2023-11-03 13:02:45 24 4
gpt4 key购买 nike

我有一个TableLayout;第一个 TableRow 的第一列是一个 CheckBoxTableLayout 和第一个 TableRow.axml 文件中创建。我在 .cs 文件中创建并填充了其余的 TableRows。每个以编程方式创建的 TableRow 的第一列也是一个 CheckBox

在第一个 TableRow 中使用 CheckBox 我想选中/取消选中所有以编程方式创建的复选框。

在 Windows 窗体应用程序中,我会通过将复选框收集到一个数组中并遍历该数组来为每个复选框设置选中的属性来完成此操作。在我的 Android 应用程序中,我不知道该怎么做。

最佳答案

您需要遍历 TableLayout 中的所有 TableRows,找到您的复选框并选中/取消选中它们。为此,请向执行以下操作的第一个复选框的点击事件添加一个监听器:

//Number of TableRows
var count = tableLayout.ChildCount;
//Position of you checkbox inside each TableRow
//TODO: make this a constant outside the listener method
var checkBoxPosition = 0;

for (int i = 0; i < count ; i++) {
var tableRow = tableLayout.GetChildAt(i) as TableRow;
if (tableRow != null) {
var checkBox = tableRow .GetChildAt(checkBoxPosition) as CheckBox;
if (checkBox != null) {
//TODO: Use state of the main checkbox here
checkBox.Checked = true;
}
}
}

关于c# - 选中/取消选中 TableLayout 中的多个复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31868352/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com