Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View.onTouchEvent only registers ACTION_DOWN event

I'm implementing a custom TextView and I want to do some action when the view is touched. I figured the onTouchEvent method would give me the full range of touches on the view without having to use setOnTouchListener (I'm trying to do all my work inside the view instead of in the activity so it's portable), but the only touch event registered is ACTION_DOWN. If I set an OnTouchListener in the activity using this, I get the full range of touch events, but onTouchEvent doesn't.

Anyone know why this is the case, or can anyone offer me a solution that doesn't involve using setOnTouchListener (Which would prevent the implementing activity from setting its own listener)?

like image 989
Jason Robinson Avatar asked Jun 17 '11 20:06

Jason Robinson


2 Answers

return true on the onTouch() event. This mean we are still waiting on some new Actions from this event so other events like OnClick() is disabled.

On action ACTION_UP you need to return false at least to not get issues with other events after it.

like image 39
niek tuytel Avatar answered Nov 09 '22 20:11

niek tuytel


You need to return true to get the following events after a down.

like image 135
hackbod Avatar answered Nov 09 '22 20:11

hackbod



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!