DraggableView class - who's the sender for the touch event?

Dave O

Well-Known Member
Licensed User
Longtime User
Short version:
When I do a CallSub from a DraggableView's touch event, is there a Sender, and if so, what is it - the DraggableView instance, the invisible panel that being dragged, or...?

Long version:
I'm creating a game with several small images that can be dragged around the screen, and I'm thinking about using panels wrapped using the DraggableView class.

I thought it might be useful to add callbacks for the Down, Move, and Up touch events, so I added those to the Initialize method:

B4X:
Sub Initialize(Activity As Activity, v As View, cbDownArg As String, cbMoveArg As String, cbUpArg As String)
    ...
    cbDown = cbDownArg
    ...

Then, in the touch event, I call the corresponding callback:

B4X:
If ACTION = ACTION_DOWN Then
   downX = x
   downY = y
   If cbDown <> "" Then
      CallSub2(Main, cbDown, Me)
   End If

That works fine, and I track the instance by passing "Me", but I wonder if I can do without the Me parameter and just use "Sender" in the sub I'm calling. I tried casting it as DraggableView, but it gives me a null exception, so I'm wondering if there's a Sender here in the called-back method, and what it is.

I've attached the project source, in case this isn't clear. Any help much appreciated!

P.S. Erel, please consider uploading DraggableView to the Libraries/Classes forum as a class file. I found it in your "classes are coming soon" post, but took me a bit to figure out that it should be copy/pasted into a new class module in my project, not put into the code inline as in your example. (Not hard, but newbies like me are easily stumped. ;^)
 

Attachments

  • puzzle1.zip
    184.1 KB · Views: 283
Top