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);
}
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With