Android Question How to detect a click at x,y

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
Hi, I have an activity wich draws a Heatmap, I need to detect in which rectangle the user clicks on.
The rectangles shape and position changes depending on the stocks data.
And the map can be scrolled up and down.
How can I do it?
See attached image.
Thaks
 

Attachments

  • Screenshot_2016-05-04-07-44-54[1].png
    91 KB · Views: 167

JordiCP

Expert
Licensed User
Longtime User
If for instance this drawing is on a Panel, you could use Panel_OnTouch() event (which gives you the touch coordinates) and handle ACTION_DOWN and ACTION_UP to decide when it is clicked
 
Upvote 0

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
Im using

B4X:
Sub PanelMap_OnTouch(Action As Int, X As Float, Y As Float)
    'If  Action = Activity.ACTION_UP Then
        Msgbox(Action&" "&X&" "&Y,"")
    'End If
End Sub   
Sub Pane1_OnTouch(Action As Int, X As Float, Y As Float)
    'If  Action = Activity.ACTION_UP Then
        Msgbox(Action&" "&X&" "&Y,"")
    'End If
   
End Sub

PanelMap is a Panel inside Panle1 but this does not work, the events are not generated.
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
It should work if it is initialized with the proper event name
B4X:
PanelMap.initialize("PanelMap")
and there is no other view on it which can consume a touch/click event. For instance if this panel has imageviews on it, they should be initizalized void
B4X:
IV.initialize("")  'for all the views contained in panelmap or added later to Panel1
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…