由网友(毁你男神、做我女人)分享简介:有没有办法获得的LinearLayout的子元素?我的code返回一个视图(LinearLayout中),但我需要把布局内访问特定的元素。Is there a way to obtain a child element of a LinearLayout? My code returns a view (linear...
有没有办法获得的LinearLayout的子元素?我的code返回一个视图(LinearLayout中),但我需要把布局内访问特定的元素。
Is there a way to obtain a child element of a LinearLayout? My code returns a view (linearlayout), but I need to get access to specific elements inside of the layout.
有什么建议?
(是的,我知道我可以使用findViewById,但我创造的布局/ Java中的孩子 - 而不是XML)
(Yes, I know I could use findViewById, but I am creating the layouts/children in java - not XML.)
推荐答案
您总是可以做这样的事情:
You can always do something like this:
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
}
相关推荐
最新文章