In short, what i am looking for is - Single swipe that triggers onClick event for multiple buttons(views) that was swiped over.
I have just started developing my first android app and am facing a problem that probably isn't that complicated but as i don't have any experience i can't piece together the solution.
I'am trying to implement a swipe over multiple buttons that would detect when they are being swiped over and trigger the onClick function. I have looked at Gestures and Flings without any success.
have tried to implement some of previous related solutions on StackOverflow:
Fling gesture detection on grid layout
Detect fling gesture over clickable items
And is it possible to dynamically draw a line from the centers of buttons that are being swiped over and are next to each other?
I was looking for a solution, and finally made it work. So I will answer here and hope it will help to someone.
I had a problem detecting a swipe with a layout with multiple buttons, so I override the method setOnTouchListener
for every button, calling inside gesturedetector.onTouchEvent(event)
(and do what you want to do with the event detected).
Obviously, to detect the button click event you only have to use setOnClickListener
method.
Maybe it's no the most elegant way to make this work, but at least worked for me.
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