Reputation: 6983
I'm making a game that has a 9 by 10 grid that is drawn in a view. This works, I would like to be able to detect when a user touches one of the cells. I know how to get keyboard events. I figure there must be a way to get a touch even with the x,y cordernat for my view with the grid.
Upvotes: 1
Views: 574
Reputation: 15
Together with setting OnTouchListener on your View object don't forget to set other views that your principle view is inside. For instance, if your layout is a LinearLayout and a Button, do you have to set OnTouchListener for both, LinearLayout and Button.
Upvotes: 0
Reputation: 43098
Simply set the OnTouchListener on your View
object. The single method to implement gets the MotionEvent
parameter. It gives you the actual coords of the touch event. See the doc.
Upvotes: 1