The list is a list of each instantiated class.
I want each class member to see every other class member that is created.
I can pass a List to the initialize method, and it fills fine with a pointer to each instantiation.
However, if I try to assign that same list to an internal List variable, I get a stack overflow. I'm guessing this is because some kind of loop occurs (but I'm not sure why it would, the List is a pointer to the Instantiation, not to the List itself... unless it recursively calls on itself when this is done)
Heres the class code
And here's the activity code:
If what I'm doing is horribly misguided, is there another way to do it such that each class member can "see" every other member internally? (I could just pass the list in every time I need it, but that doesn't seem elegant)
Ross
I want each class member to see every other class member that is created.
I can pass a List to the initialize method, and it fills fine with a pointer to each instantiation.
However, if I try to assign that same list to an internal List variable, I get a stack overflow. I'm guessing this is because some kind of loop occurs (but I'm not sure why it would, the List is a pointer to the Instantiation, not to the List itself... unless it recursively calls on itself when this is done)
Heres the class code
B4X:
'Class module
Sub Class_Globals
Public asView As Button
Private myClearWindow As Label
Private originalX, originalY As Int
Private holdingView As Panel
Private Gesture As Gestures
Private listAllTrickButtons As List
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(ViewHoldingButton As Panel, listButtons As List)
asView.Initialize("myButton")
myClearWindow.Initialize("myClearWindow")
holdingView = ViewHoldingButton
listButtons.Add(Me)
'------------- I first got the error here, so thought I would wait til all buttons instantiated
'listAllTrickButtons = listButtons
Gesture.SetOnTouchListener(myClearWindow, "Gestures_Touch")
End Sub
Public Sub StartMe
holdingView.AddView(myClearWindow, asView.Left, asView.Top, asView.Width, asView.Height)
holdingView.Color = Colors.Transparent
End Sub
'---------------- this is the error code
Public Sub setTrackerList(listButtons As List)
listAllTrickButtons = listButtons
End Sub
Sub Gestures_Touch(View As Object, PointerID As Int, Action As Int, X As Float, Y As Float) As Boolean
If Action = Gesture.ACTION_DOWN Then
originalX = asView.Left
originalY = asView.Top
Return True
End If
If Action = Gesture.ACTION_MOVE Then
Log(PointerID)
asView.Left = X + originalX - asView.Width/2
asView.Top = Y + originalY - asView.Height - 20dip
Return True
End If
If Action = Gesture.ACTION_UP Then
asView.Left = originalX
asView.Top = originalY
End If
End Sub
And here's the activity code:
B4X:
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
Dim aPanel As Panel
aPanel.Initialize("apanel")
Activity.AddView(aPanel, 0, 0, 100%x, 100%y)
Dim listButtons As List
listButtons.Initialize
For i = 0 To 4
Dim btn As trickButton2
btn.Initialize(aPanel, listButtons)
aPanel.AddView(btn.asView, i * 50dip + 50dip, 100dip, 40dip, 40dip)
btn.asView.Text = i
btn.StartMe
Next
For Each btn As trickButton2 In listButtons
btn.TrackerList = listButtons
Next
End Sub
If what I'm doing is horribly misguided, is there another way to do it such that each class member can "see" every other member internally? (I could just pass the list in every time I need it, but that doesn't seem elegant)
Ross