Android Question Control Programmatically Added Labels

amiria703

Member
Hi!
I have some labels added to a scrollview programmatically.
User determines the amount of labels.
I named them lbl1.
I need the whole lbl1 of each labels.
But the last one is just have lbl1 as its name.
 
Last edited:

Midimaster

Active Member
Licensed User
If you want to keep the access to all your labels, you can add them into a list. To tell apart them, all the labels should get a different TAG property:
B4X:
Sub Process_Globals
    Private counter As Int
End Sub

Sub Globals
    Private Scroll As ScrollView
    Private LabelList As List
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
    LabelList.Initialize
    Scroll.Height=500
    For i=0 To 9
        Dim lbl As Label
        lbl.Initialize("lbl")
        lbl.Tag=i
        Scroll.Panel.AddView(lbl,0,i*60,200,50)
        lbl.Text="Label " & i
        LabelList.Add(lbl)
    Next
End Sub

Sub Button1_Click
    counter=(counter + 1 ) Mod LabelList.Size
    Dim lbl As Label=LabelList.get(counter)
    lbl.Color=Colors.Red
End Sub

Sub lbl_Click()
    Dim lbl As Label = Sender
    Log(lbl.Tag)
End Sub
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…