Add View (control) at Runtime

TedN

Member
Licensed User
Longtime User
Is there a tutorial or example of how to add a label (or any view) at runtime.

AddView seems pretty straightforward but I can't seem to get it to work.

Code: Copy
Sub EditMode()
     Dim lblControls As Label

     AddView(lblControls, 10, 20, 100, 200)
End Sub

I'm getting error: Undeclared variable 'addview' is used before it was assigned any value.
 
Thanks for reply. I get no errors now but nothing appears on the emulator.

My revised code is as follows:

Code: Copy
Sub Activity_Create(FirstTime As Boolean)

   Activity.LoadLayout("Main")
   EditMode
   
End Sub

Sub EditMode()
   
   Dim lblControls As Label
   lblControls.Initialize("controls")
   lblControls.Color = 255
   lblControls.Text = "TEST"
   lblControls.TextColor = 0
   lblControls.BringToFront
   Activity.AddView(lblControls, 10, 20, 100, 200)
   
End Sub
 
Upvote 0
That is because you have a transparent label on a black background with black text.

Try modifying the line to
Code: Copy
lblControls.TextColor = Colors.Cyan
and you should see the text.
 
Last edited:
Upvote 0
Back
Top