Creating 'label' at runtime

vecino

Well-Known Member
Licensed User
Longtime User
Hi, I'm asking so many questions, but questions arise I can not find the solution in the forums.
I need to create many 'label' at runtime and then give your property values ​​"Text", the problem is that I like to do it by code, but I can not. Here insert a piece of code to understand what you intend to do.

B4X:
Sub Globals
  Dim pn1 As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
  Activity.LoadLayout("Fcreateviewsruntime")   

  Dim i, iHeight As Int
  Dim lb As String

  For i=1 To 5            
    lb&i.Initialize(lb&i)   
    lb&i.TextColor = Colors.Black
    lb&i.Color = Colors.LightGray
    lb&i.Gravity = Bit.OR(Gravity.RIGHT,Gravity.CENTER_VERTICAL)
    lb&i.Height = iHeight
    lb&i.Text = "label: "&i      
    pn1.AddView(lb&i,10dip,(iHeight*i)+2dip,60dip,iHeight)
  Next
   
End Sub

Thanks for your help
Greetings.
 
Top