Reputation: 533
I am having an issue with MotionEvent.ACTION_UP The event is called before I lift my finger.
Here is the code I am using. What should I change? Thanks for any help!
public boolean onTouchEvent(MotionEvent e) {
switch(e.getAction()) {
case MotionEvent.ACTION_DOWN:
if(checkColide(e.getX(), e.getY())) {
isFootballTouched = true;
downT = c.MILLISECOND;
downX = e.getX();
}
break;
case MotionEvent.ACTION_MOVE:
//moveFootball(e.getX(), e.getY());
break;
case MotionEvent.ACTION_UP:
upT = c.MILLISECOND;
upX = e.getX();
getVelocity();
break;
}
return false;
}
Upvotes: 2
Views: 1578
Reputation: 304
Try returning true if one of this 3 case occurred
public boolean onTouchEvent(MotionEvent e) {
switch(e.getAction()) {
case MotionEvent.ACTION_DOWN:
if(checkColide(e.getX(), e.getY())) {
isFootballTouched = true;
downT = c.MILLISECOND;
downX = e.getX();
}
return true;
case MotionEvent.ACTION_MOVE:
//moveFootball(e.getX(), e.getY());
return true;
case MotionEvent.ACTION_UP:
upT = c.MILLISECOND;
upX = e.getX();
getVelocity();
return true;
}
return false;
}
Upvotes: 3
Reputation: 40203
Probably you should return true
from the onTouchEvent()
. Returning false
means that you're not interested in receiving events to this View
anymore. Hope this helps.
Upvotes: 1