Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Triggering multiple buttons(onClick event) with one swipe/gesture

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?

like image 869
kitaps Avatar asked Nov 21 '12 19:11

kitaps


1 Answers

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.

like image 113
qgadrian Avatar answered Oct 28 '22 13:10

qgadrian