Onclicklistener In Canvas
Im developing an application which having Images as a Index on selection of particular image that activity will begin but I dont know how to set onClickListener or onTouchListener
Solution 1:
try something like this:
public boolean onTouch(View v, MotionEvent event) {
if((event.getX(0)>=160) &&
(event.getY(0)>=100) &&
( event.getX(0)<=160+BOOK_IMG_WIDTH) &&
(event.getY(0)<=100+BOOK_IMG_HEIGHT))
{
//book selected
}
returntrue;
}
Solution 2:
Use ImageView
instead of bitmap and add it to your layout:
book = newImageView(context);
book.setImageResource(R.drawable.book);
book.setOnTouchListener(newView.OnTouchListener() {
publicbooleanonTouch(View v, MotionEvent event) {
/*...*/
}
};);
Post a Comment for "Onclicklistener In Canvas"