简体   繁体   中英

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;       
}

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;       

}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM