I had the same problem until recently. I'm new to android and not sure
whether this is the optimal way of solving it, but it's simple and
allows you to manage the sensitivity of the click.
@Override
public boolean onTouchEvent(MotionEvent event)
{
if(event.getAction() == MotionEvent.ACTION_DOWN)
{
xTouch = (int) event.getX();
yTouch = (int) event.getY();
xClickOffset = xTouch; *****************
yClickOffset = yTouch; ****************
}
else if(event.getAction() == MotionEvent.ACTION_MOVE)
{
xOffset += xTouch - (int) event.getX(); // offsets for
scrolling the game board and other stuff here, isn't related to
clicking
yOffset += yTouch - (int) event.getY();
xTouch = (int) event.getX();
yTouch = (int) event.getY();
}
else if (event.getAction() == MotionEvent.ACTION_UP)
{
if(Math.abs(event.getX() - xClickOffset) < tileSize / 2 &&
Math.abs(event.getY() - yClickOffset) < tileSize / 2)
*************************
{
//do click logic
}
}
return true;
}
I marked the important lines so you can see them, this is a simple
example and I'm sure you will easily adapt it for your code.
Basically, it checks whether the movement that has happened since
pressing down is very little. If it is - it's a click.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en