Android - 让孩子进入一个视图? [英] Android - get children inside a View?
本文介绍了Android - 让孩子进入一个视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定一个视图,如何在其中获取子视图?
Given a View how can I get the child views inside it?
所以我有一个自定义视图,调试器显示在 mChildren
下还有 7 个其他视图.我需要一种方法来访问这些视图,但似乎没有公共 API 可以做到这一点.
So I have a custom View and debugger shows that under mChildren
there are 7 other views.
I need a way to access these views but it doesn't seem like there is a public API to do this.
有什么建议吗?
我的自定义视图继承自 AdapterView
My custom view inherits from AdapterView
推荐答案
for(int index = 0; index < ((ViewGroup) viewGroup).getChildCount(); index++) {
View nextChild = ((ViewGroup) viewGroup).getChildAt(index);
}
可以吗?
这篇关于Android - 让孩子进入一个视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文