Panel touch help

noclass1980

Active Member
Licensed User
Longtime User
HI,

I've created a number of sliding panels with a simple for next loop using the AHViewPager. They work fine but I want to know how I can get a touch event for (say) panel number 2. Panel number 2 has an image view with circles overlaid on it and I want to identify the name of the circle when the user touches the screen so I need the X and Y coordinates returned. I've tried various touch events but nothing seems to work.
Any suggestions?
Part of the panel setup sub is shown below
B4X:
For i = 0 To 4
Dim pan As Panel

Select i
Case 0
pan = CreatePanel(TYPE_HomePage, "Information")
container.AddPage(pan,"Page 1 - Home Page")
allpanels(i)=pan
Case 1
pan = CreatePanel(TYPE_HomePage, "Data Input")
container.AddPage(pan,"Page 2 - DataInput")
allpanels(i)=pan
Case 2
'TYPE_Chart = 3
pan = CreatePanel(TYPE_HomePage, "Data Chart " )
container.AddPage(pan,"Page 3 - Data Chart" )
allpanels(i)=pan

Dim r As Reflector 'added this but didn't work
r.Target=allpanels(2)
r.SetOnTouchListener(Panel2touch) 'Panel2touch is a sub which just shows a ToastMessage for debugging purposes

Case 3
pan = CreatePanel(TYPE_HomePage, "Other Chart " )
container.AddPage(pan,"Page 4 - other Input" )
allpanels(i)=pan
Case Else
pan = CreatePanel(TYPE_HomePage, "Other Chart " )
container.AddPage(pan,"Page 5 - Other Chart" )
allpanels(i)=pan

End Select
Next

I've managed to solve this based on the thread here .

There was an error in the code above. it should be
B4X:
r.SetOnTouchListener("Panel2touch")

the Dim r as Reflector is now in the Sub Globals

and the Panel2touch sub is now

B4X:
Sub Panel2touch(viewtag As Object, action As Int, X As Float, Y As Float, motionevent As Object) As Boolean
If action=Activity.ACTION_DOWN Then 
ToastMessageShow("Panel 2 touched!",False)
End If
End Sub

Just goes to show if you keep on searching, you'll find it eventually!

Liking the 2.71 version alot!
 
Last edited:
Top