ScrollView Ignore OnTouch while scrolling?

I have a ScrollView -> Table => TableRow, in which I dynamically add rows, each row has a LinearLayout inside it, to which I attach an OnTouchListener, and then when it touches, I do something. At least it was a plan, the problem I am facing is that when you scroll the ScrollView, even when scrolling, it disables these events. This type of behavior does not occur for other controls that I have in ScrollView, such as buttons, image buttons, EditText

My question is how to make LinearLayout ignore these OnTouch events while the ScrollView scrolls, like the Button and EditText fields?

+4
source share
1 answer

Inside the onTouch event callback, add an if or case statement to the one that checks

(me.getAction == MotionEvent.ACTION_CANCEL) similar to this:

 else if (me.getAction() == MotionEvent.ACTION_CANCEL){ Log.i(myTag, "Action Cancel"); //This means we are scrolling on the list, not trying to press } 

It has been a long time since I worked on this, but I know that I needed to solve this problem at some point, and, looking now, I think that this is what I had to do to make its working, He will continue to receive callbacks while the list scrolls, but the action on them must be undone. Therefore, if you configured some type of if or switch / case that checks action_cancel and does nothing when it is true, from the point of view of users, onTouch will β€œignore” the events that occur during scrolling.

+5
source

Source: https://habr.com/ru/post/1394026/


All Articles