Adem
Adem

Reputation: 9429

why I always get ACTION_DOWN from onTouchEvent

I extend my class from View. and I override onTouchEvent function. But, I can get only ACTION_DOWN event. not any ACTION_UP or ACTION_MOVE. what should I do to get that events ?

I override only onTouchEvent and onDraw function. and there is only this view in application

@Override
public boolean onTouchEvent(MotionEvent event) {
    System.out.println("event:"+event.getAction());
    return super.onTouchEvent(event);
}

Upvotes: 9

Views: 6511

Answers (2)

Jacksonkr
Jacksonkr

Reputation: 32217

At work we had a LinearLayout called teaser which was having similar issues (it's been a while). Anyway, we found that this "hack" seems to help get some extra responsiveness out of a touch.

teaser.setOnTouchListener(new OnTouchListener() {
    public boolean onTouch(View v, MotionEvent motionEvent) {
        TransitionDrawable transition = (TransitionDrawable) v.getBackground();

        switch(motionEvent.getAction()) {
            case MotionEvent.ACTION_DOWN:
                if(transition != null) transition.startTransition(250);
                break;
            case MotionEvent.ACTION_UP:
                loadArticle(position);
            case MotionEvent.ACTION_CANCEL:
                if(transition != null) transition.reverseTransition(0);
                break;
        }
        return false;
    }
});

// Has to be here for the touch to work properly.
teaser.setOnClickListener(null); // <-- the important part for you

I honestly couldn't give you any rhyme or reason to it, but hopefully that helps.

Upvotes: 1

Peterdk
Peterdk

Reputation: 16015

Possibly you need to return true instead of returning the super event. That means that you handled that event, and thus you can receive the next one.

Upvotes: 31

Related Questions