从LinearLayout中获取子元素 [英] Getting child elements from LinearLayout
本文介绍了从LinearLayout中获取子元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法获得的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
}
这篇关于从LinearLayout中获取子元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文