Dears, below a simple application, the problem is when i first run it works correctly( and it shows 2 buttons
) but in the second run it shows only 1 button and in the 3rd run the button disappeared, do you have any explanation for this, and how can i solve this problem???
) but in the second run it shows only 1 button and in the 3rd run the button disappeared, do you have any explanation for this, and how can i solve this problem???
B4X:
Activity module
Sub Process_Globals
Dim id As Int
End Sub
Sub Globals
' Dim ExitBtn As Button :ExitBtn.Initialize ("ExitBtn1")
Dim objParent1 As Parent
Dim Pnl As Panel:Pnl.Initialize ("aaa"):Pnl.Color=Colors.White
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.AddView(Pnl,0,0,100%x,100%y)
' Pnl.AddView(ExitBtn,0,90%y,100%x,10%y)
objParent1.Initialize(Pnl,Activity.Width , Activity.Height)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
'Sub ExitBtn1
'Activity.Finish
'End Sub
B4X:
'Parent Class
Sub Class_Globals
Dim PagePanel As Panel
Dim Ch(2) As Chiled
Dim id As Int
End Sub
Public Sub Initialize(pnal As Panel,ptop As Float, pheight As Float)
PagePanel=pnal
id=Main.id
Ch(0).Initialize(Main.id, "BAD",Me)
Main.id=Main.id+1
Ch(1).Initialize(Main.id, "Good",Me)
End Sub
Public Sub ChildManager( ptag As Int)'ch As Chiled,
Msgbox ("chiled click for parent: "&id , ptag)
End Sub
Public Sub Add(Btn As Button,ObjectId As Int)
PagePanel.AddView(Btn, 50%x*ObjectId,0, 30%x,30%x)
End Sub
Public Sub ChangeMyColor(BtnId As Int)
Ch(BtnId).btnChild.Color=Colors.Red
End Sub
B4X:
'Chiled Class
Sub Class_Globals
Public btnChild As Button
Dim ObjectParent As Object'Passed as me from the parent object
Dim ObjectId As Int
End Sub
Public Sub Initialize(ChlildId As Int, txt As String,pParent As Object)
ObjectParent = pParent
btnChild.Initialize("Child")
ObjectId=ChlildId
btnChild.Tag=ChlildId
btnChild.Text=txt
AddButtonToPagePanel(btnChild,ObjectId)
End Sub
Sub Child_Click
Dim b As Button
b = Sender
CallSub2(ObjectParent , "ChildManager", b.tag)
CallSub2(ObjectParent , "ChangeMyColor", b.tag)
End Sub
Sub AddButtonToPagePanel(Btn As Button,ObjectId1 As Int)
CallSub3(ObjectParent,"Add",Btn,ObjectId1)
End Sub