I am having trouble trying to use Gesture Detector with views created in an array.
B4X:
Sub Process_Globals
Dim GD As GestureDetector
End Sub
Sub Globals
Dim p(20) As Panel
End Sub
Sub Activity_Create(FirstTime As Boolean)
For i=1 To 20
p(i).Initialize("p")
Activity.AddView(p(i), 0, (i-1)*85dip, 100%x, 70dip)
p(i).Tag = i
GD.SetOnGestureListener(p(i), "Gesture")
Next
End Sub
Sub Gesture_onTouch(Action As Int, X As Float, Y As Float, MotionEvent As Object)
Dim pnl As Panel
pnl = Sender
p(pnl.Tag).Color = Colors.Green
End Sub
Sender doesn't appear to work with Gesture Detector. I need to be able to detect swipes, clicks, drags, and long presses and know which panel was touched.
Any suggestions appreciated
I looked at my code and saw nothing wrong. The sender is correctly returned. BUT you must instantiate a GD detector for every view. That means: if you have 20 panels, you must declare 20 GD.
To solve your problem, add Dim gd(20) as GestureDetector in Globals and replace your SetOnGestureListener with:
GD(i).SetOnGestureListener(p(i), "Gesture")
SetOnGestureListener binds a view to a gesture detector instance.
Maybe I could change that because it's not intuitive.