For the purposes of say game development, is it possible to set up a view and create a class that extends button or implements clickable or something. Im trying to figure out the best way to handle screen clicks on moving objects onscreen and right now Im drawing everything in a canvas which inturn is drawn to a view but I cant make individual bitmaps representing objects clickable.
So before I throw out a lot of work already and try for it does anyone know if its possible to have dynamically moving objects within a view that can independently handle screen clicks.
Add an OnTouchListener
to your view (the one that that draws all your objects on the canvas), and in the onTouch(View v, MotionEvent event)
, get the coordinates of the event:
int x = event.getX();
int y = event.getY();
Then loop through your objects that you draw and see if these coordinates are on that objects current area, if so, you know that it has been clicked.