I am creating an android app in Java in which I have a lot of <TextView>
around the screen, all of them with onTouchListeners defined. They are wrapped in a <ScrollView>
because they occupy more space than available in the screen.
My problem is: when I scroll the app, up/down, by touching at the screen and moving my finger up/down, the scroll works as expected but the onTouchListener of the touched <TextView>
is also fired (which is probably expected as well) - I don't want that to happen though. I want the onTouchListener to be ignored when I'm touching the screen to scroll it.
How can I accomplish this? I don't want my function to run when the user is scrolling and "accidentally" fires the onTouchListener on a certain <TextView>
.
After searching more, I found this solution by Stimsoni. The idea is to check if the time between the
ACTION_DOWN
andACTION_UP
events is lower or higher than the value given byViewConfiguration.getTapTimeout()
.From the documentation:
Code: