Android Question Delegating Events

boten

Active Member
Licensed User
Longtime User
I think this can NOT be done, but you may show me this is possible.
Here is the situation:
I have a panel covering most (or all) of the screen.
On this panel I have many labels (about 45 labels)
Each label should respond to a Click/LongClick event
The "underneath" panel should respond to swipes (event _Touch; DOWN,MOVE,UP)
The problem is that the labels consume any touch (clicks) so the panel does not receive the Touch event.

Even if I put another transparent panel on top of everything I still have the same problem, only reversed:
This new panel will consume its Touch event and the labels underneath it will not receive the Click/LongClick events.

Is there a way to "delegate" an event from one view to another view "below" it?

I know that Click and Touch can "interfere" with one another, so I will settle for a LongClick on the labels.

Will it make any solution easier/harder if the labels were just small panels?
 
Last edited:

thedesolatesoul

Expert
Licensed User
Longtime User
If you just remove the label_Click subs, the events will be sent to the next view in the hierarchy.

If you put a panel on top, but in the touch event, if you do not detect the gesture you need to return true/false (cannot remember which one), if you want the event to pass through to underlying views.
 
Upvote 0

boten

Active Member
Licensed User
Longtime User
I tried the panel on top of everything. Problem is: the Touch event "pattern" does not return a value. Even when I declare the _Touch sub to return boolean it doesn't help. Returning False (and returning True) does not delegate it to the underlaying label/panel.
 
Upvote 0

boten

Active Member
Licensed User
Longtime User
The solution I can think of is cumbersome:
1) Catch only the _Touch event on the labels
2) On DOWN: a) Keep positions X0,Y0 b) start a timer for 1/4 or 1/2 sec.
3) On MOVE: keep positions X1,Y1
4) On UP: if "distance traveled" is beyond label's borders treat it as swipe. If confined to label's border treat it as click
5) When timer expires: if "distance" is beyond label's borders treat it as swipe. If confined to label's border treat it as long-click

I was hoping for a simpler solution :(
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
I think this was adresed in a very old thread of b4ppc(basic4winmob).
If I recall correctly, the solution was to only catch the panel touch events, figure out if it was a swipe, and if not, figure out the closest labels an fire it's event...

I cannot give you a proper code, but it shouldn't be too difficult if you know how to work out grid coordinates
 
Upvote 0

boten

Active Member
Licensed User
Longtime User
Solved with GestureDetector
1) set a listener for the big panel
2) set a listener for each label on this panel
3) _OnTouch for big panel. DOWN: save initial position UP: compute distance. If big enough, perform the swipe
4) _OnTouch for label. DOWN: save initial position UP: compute distance. If big enough, perform the swipe
5) _onLongPress for label: perform long-click action

#4 is needed (_OnTouch for label) because a swipe action can begin on a label and not only on the big panel

Thanks thedesolatesoul for pointing me in the right directionhttps://www.b4x.com/android/forum/members/thedesolatesoul.11412/
 
Upvote 0
Top