tags:

views:

136

answers:

2

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?

A: 

Using Views sounds like its going to be brutally difficult to render anything well if there is movement. You probably want to be drawing to a Canvas or using OpenGL unless you're doing something really static. Here's a great talk from last years I/O conference on making Android games. Its kind of long and you can skip about 15 minutes in. Also the source is available. That should give you a good idea of ways to go about things

jqpubliq
Yeah, I made need to do it a different way, but I'm going to try this first. It's a casual game.
Slapout
A: 

@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.

Romain Guy
Thanks! That's exactly what I was looking for.
Slapout