有没有办法获取LinearLayout的子元素?我的代码返回一个 View (线性布局),但我需要访问布局内的特定元素。
有什么建议吗?
(是的,我知道我可以使用 findViewById,但我是在 java 中创建布局/子项 - 而不是 XML。)
最佳答案
你总是可以这样做:
LinearLayout layout = setupLayout();
int count = layout.getChildCount();
View v = null;
for(int i=0; i<count; i++) {
v = layout.getChildAt(i);
//do something with your child element
}
关于java - 从 LinearLayout 获取子元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6615723/