android


Android - Is it possible to have dynamically moving clickable objects in a view


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.

Related Links

Is there any way to load 5 - 10 items in recyclerview at a time instead of 50k?
How does Fragment Navigation Drawer open from right to left?
Top margin for first item in navigation drawer menu in Android Studio
How to configure a virtual Genymotion or AVD capable of supporting dual sim card?
Xamarin Android Webview Linkify email addresses
Mocking method calls using power mockito - org.powermock.api.mockito.ClassNotPreparedException
NetworkOnMainThread error still
Android tab with navigation
Soap response “ButtonId” checking at layout if exist
java.lang.RuntimeException: Handler sending message to a Handler on a dead thread
Cyanogenmod 13 brunch i9500 failed
Android sliding app
Tried adding ScrollView to my layout, but it crashes my app
android opengl es 2 display after several rotate error
ADV manager error
Android: How to avoid ImageView flashing when the screen is clicked?

Categories

HOME
algorithm
assembly
deep-learning
ng-idle
merge
forms
mjml
oracle-apex-5
spring-data-redis
grafana
rendering
replace
pyqt4
onclick
odoo-8
opengl-3
qpython
magnetic-cards
internationalization
foreign-keys
google-api-client
data.stackexchange.com
surveymonkey
outliers
failover
recurring-events
sql-server-2000
hreflang
github3.py
sim-toolkit
reason
parse-tree
docfx
modernizr
comparison-operators
branching-and-merging
glm-math
rfc3339
optimizely
openal
term
globalize
geotiff
rserve
tinymce-3
insight
colorbar
opengl-4
ngmaterial
bbpress
flac
smartfoxserver
node-request
autosar
dotnetnuke-7
hclust
vorpal.js
android-wake-lock
http-status-code-401
bizagi
dbamp
turbo-prolog
phpwebsocket
lz77
html-to-pdf
pushbots
piracy-prevention
ess
fuelcms
zen-cart
doctype
matlab-deployment
fail2ban
umlgraph
nodelist
metatrader5
psr-4
strawberry-perl
mobility
live555
radiant
fpdi
gae-quotas
square-bracket
away3d
unit-of-work
nebula
stacky
chart-director
http-status-code-410
dopostback
redis-py
mkv
vfs
thttpd
ikimagebrowserview
event-receiver
addchild
django-piston
strtod
interop-domino
pnrp

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App