7

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?

Community
  • 1
  • 1
kitaps
  • 243
  • 4
  • 10

2 Answers2

3

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.

qgadrian
  • 617
  • 1
  • 14
  • 26
0

you could just overwrite the onTouch method of the buttons to find out if a Button was touched. That would be triggered while swiping over the button. From there you could call the method that was supposed to be triggered by the onClickEvent.

To draw the lines between the buttons you could define them in your xml and just switch the visibility if two buttons are activated by the same swipe.

Marc_Bob
  • 119
  • 7