Android Question SetOnTouchListener reports only DOWN events

Brian Dean

Well-Known Member
Licensed User
Longtime User
When I use this code to replace the usual B4A touch event handler ...

B4X:
    Dim rf As Reflector
    rf.Target = pnlOne
    rf.SetOnTouchListener("pnlOne_Touch")
    . . .
    . . .

    Sub pnlOne_Touch (viewtag As Object, action As Int, X As Float, Y As Float, motionevent As Object) As Boolean

... the motionevent value returned to pnlOne_Touch reports only DOWN events. This does not seem right. How can I get the other touch events?
 

drgottjr

Expert
Licensed User
Longtime User
consume the event. i think you may have missed the most important part of the post where you found the code.
 

Attachments

  • touch.png
    touch.png
    21.6 KB · Views: 159
Last edited:
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
Consume the event.
Yes - that fixes the problem (thanks), but removes the objective of this code which was to pass the event on to underlying views.

I think you may have missed the most important part of the post where you found the code.
I picked the code out of this post. I cannot see what I have missed.

Is there a way to intercept all touch events while passing those events on to underlying views?
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
I think the situation may be analogous to where Windows controls can 'capture' the mouse to receive motion events even when the user moves the cursor outside the bounds of the control. I think a similar thing is happening here for a similar reason. As this is a characteristic of, and controlled by, low level code in the OS then I don't think there is anything you can except perhaps call the event Subs of the underlying views in your panel event Sub.
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
I don't think there is anything you can except perhaps call the event Subs of the underlying views
Okay - thanks. I did think of trying that, but I raised this thread as a result of failing to answer fully someone else's problem in another thread. There the underlying view was a CLV and the requirement was to pass through scroll gestures, and I am not sure how to deal with those. But, for my education, I will experiment with some other types of view.
 
Upvote 0
Top