通过一个Android视图所有子视图循环? [英] Loop through all subviews of an Android view?

查看:140
本文介绍了通过一个Android视图所有子视图循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个游戏为Android。为了帮助实现它,我的想法是创建一个视图的子类。然后,我会插入这个类的几个实例为主要观点的儿童。每个实例会处理检测时,它是pssed(通过OnTouchListener)$ P $。

I’m working on a game for Android. To help implement it, my idea is to create a subclass of a view. I would then insert several instances of this class as children of the main view. Each instance would handle detecting when it was pressed (via OnTouchListener).

我有现在的问题是我怎么通过这些子视图循环,这样我可以阅读他们的状态和处理它们? (即当它们都达到一定的状态的东西应该发生)。

The problem I’m having now is how do I loop through all these sub-views so I can read their statuses and process them? (I.e. when they all reach a certain state something should happen).

还是有更好的方式来在屏幕上的几个对象响应触摸和其状态,我可以检查?

Or is there a better way to have several objects on the screen that respond to touch and whose status I can check?

推荐答案

@jqpubliq是正确的,但如果你真的想通过所有的意见,你可以简单地使用getChildCount()和getChildAt()方法从ViewGroup中。一个简单的递归方法将做休息。

@jqpubliq Is right but if you really want to go through all Views you can simply use the getChildCount() and getChildAt() methods from ViewGroup. A simple recursive method will do the rest.

这篇关于通过一个Android视图所有子视图循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆