How does one add a button to a panel in code

fdx12345

Active Member
Licensed User
I have easily done this with the designer but need to know how to do it in code. Given how to add a button, I can use the same steps to add labels, ect.

Thanks for the help in advance.
 

mangojack

Well-Known Member
Licensed User
B4X:
Sub Globals
   
   'declare the views
   Dim pnlTest As Panel
   Dim btnOK As Button

End Sub

Sub Activity_Create(FirstTime As Boolean)
   
   'initialize the Panel ,  no event is assigned to the panel ("")
   pnlTest.Initialize("")
   
   'add the panel to Activity (View,Left,Top,Width,Height)
   Activity.AddView(pnlTest,0dip,0dip,100%x,100%y)
   
   'initialize the button and assign an Event to the button (btnOK)
   btnOK.Initialize("btnOK")
   btnOK.Text="OK   Click Me"
   
   'add the button to the Panel (View,Left,Top,Width,Height)
   pnlTest.AddView(btnOK,200dip,200dip,200dip,50dip)
   
End Sub

Sub btnOK_Click
   
   Msgbox("You have just pressed the button ..Whoopee","Button Test")

End Sub
Cheers mj
 
Top