我的 TableLayout 有很多行,我想访问按钮 View 。示例如下:
<TableLayout>
<TableRow>
<Button />
<Button />
</TableRow>
<TableRow>
<Button />
<Button />
</TableRow>
</TableLayout>
从表格布局中,我想循环浏览按钮。
TableLayout layout=(TableLayout) findViewById(R.id.Layout);
layout.getChildCount;
以上仅返回表格行 View 数。
最佳答案
试试这样,可能对你有帮助
TableLayout layout = (TableLayout) findViewById(R.id.Table_ID);
for (int i = 0; i < layout.getChildCount(); i++) {
View child = layout.getChildAt(i);
if (child instanceof TableRow) {
TableRow row = (TableRow) child;
for (int x = 0; x < row.getChildCount(); x++) {
View view = row.getChildAt(x);//Here you get Your Button View
}
}
}
关于java - 子元素的子元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37744926/