linuxer
linuxer

Reputation: 533

MotionEvent.Action_up called to early

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

Answers (2)

coemu
coemu

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

Egor
Egor

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

Related Questions