Reputation: 11
I have images that want to interactive in android, please help me how I can make interactive image in android, I'm new user on this site, may be site is not allow me to post image.
My scenario is, I have 10 chairs around table, and I want user interactive with chair (Click able) and goes to other screen. I'm new to android. Please explain how I can create interactive images for my apps.
Here is an image that helps you understand my scenario:
Upvotes: 0
Views: 3204
Reputation: 5900
Just set OnTouchListener to your image view with onTouchEvent
method like this one:
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
x = event.getX() + this.getLeft();
y = event.getY() + this.getTop();
// check if (x,y) is on chair and do other staff
}
return super.onTouchEvent(event);
}
(x,y) is a point on picture which was clicked. Save ranges of picture's point which are on chairs. Than just check on which one you've clicked and do appropriate staff.
Upvotes: 1
Reputation: 2519
keep all the chair images as separate ImageButton and use on Click listener for image views. Like for any chair x
ImageButton xchair = (ImageView)findViewById(R.id.xchair);
xchair.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
**Call intent for calling another activity here.**
}
});
Upvotes: 0