0

How do I stop a gesture listener from listening after a method has been called as a result of the touch event that has already happened.

Confusing, I know.

In steps,

  1. User touches screen and scrolls a certain distance
  2. Event is triggered based on distance scrolled/or speed; doesn't matter
  3. If user holds finger on screen, it continues to calculate
  4. Randomness occurs due to these calculations

How can one stop this from listening until the finger is replaced on the screen?

Does the GestureListener have a stop protocol method or something, I can envision onLift or something?

Do I need to unattach the listeners?

Any help is appreciated

shanehoban
  • 870
  • 1
  • 9
  • 30

1 Answers1

0

If you have control over the method that trigger the event and over the touch listener, use a boolean to decide if you need to call it.

public boolean onTouch(View v, MotionEvent event) {
  switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        eventShouldBeTriggered = true;
        }
//Other touch logic
}

triggerEvent(){
 if(eventShouldBeTriggered){
       eventShouldBeTriggered = false;

       //event logic

  }
}
David Corsalini
  • 7,958
  • 8
  • 41
  • 66
  • Maybe I should have mentioned. I'm working with onScroll, and I need to stop the onScroll method from listening. I want to exit the onScroll method as soon as the criteria is met - and not allow it until the user re-touches the screen. Thanks for the input, but I don't see how the code provided can help in this situation – shanehoban May 23 '14 at 11:29
  • You need to stop scrolling or onScroll method? Those are 2 very different things. – David Corsalini May 23 '14 at 11:55
  • Perhaps I don't understand how the onScroll method from SimpleOnGestureListener works. The problem became apparent when I held my finger on the screen after the criteria was met (i.e. I scrolled with a certain speed). The next iteration occurred even though my finger did not move. I need it to stop calling onScroll, until the finger has lifted from the view (or screen) and re-touched. – shanehoban May 23 '14 at 12:00
  • @shanehoban How you resolved the issue ? I have the same scenario. – Menu Jul 28 '21 at 08:49