# Android-Handling screen clicks for dynamically moving objects in a view

I have a kind of broad question to ask but I have to start some where so.....What is the best way to handle onscreen clicks for moving objects being drawn on a canvas in a view. Im registering the screen clicks just fine and Im able to get the x and y but when it comes to matching it to an object on screen Im at a loss. I have a really hacky way of traversing through an array of existing objects and checking their onscreen coordinates against the coordinates of each item in the array but its no where near reliable and doesnt work most of the time. when it does work the click ends up not matching the item I clicked on. At the moment this all takes place in a custom view and is being drawn on a canvas but in the future Im going to implement it all in opengl when I have the time.....or the money to pay some one else :0)

Any opinions, links to tutorials, or suggestions would be much appreciated thanks.

I don't think traversing an array of on-screen objects is too hackish because at some level you're going to need to check each clickable area against each click. And it can really be as simple as just taking an array and testing RectF against x,y coords using RectF.contains(). The alternative is using some space partitioning, like a BSP, but that's almost certainly more than you need.
As for reliability, you might be running into emulator speed issues. The emulator is slow and takes a little while (sometimes like 0.1 seconds for me) to register touch events. By the time the code gets the event, the objects have moved. This part may be easier to debug on a real device. If, on the other hand, you have stationary objects, then it's probably just buggy code. logcat is your bff.