Android Question array of labels

sina39000

Member
My code:
B4X:
Sub Globals
    Private Label1 As Label
    Private Label2 As Label
    Private Label3 As Label
    Private Label4 As Label
    Private Label5 As Label

    Private LLL() As Label
    LLL = Array As Label (Label1,Label2, Label3, Label4, Label5)
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout1")
    For i = 1 To 4
        LLL(i).Initialize("L"&i)
        LLL(i).Text = "Label No "&i
        LLL(i).Color = Colors.Blue
    Next
End Sub

Label1 to Label5 defined in designer
nothing on run and labels do not changes
what is wrong???
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

klaus

Expert
Licensed User
Longtime User
As Don Manfred allready said, you must NOT initialize the Labels again!
In your code, Label5 will not be changed.
Change For i = 1 To 4 to For i = 0 To 4 !
If you use any event with the Labels you should use the Tag property and set the Event Name the same for all Labels in the Designer.
And in the Event routine use the Sender keyword to get the calling Label.
 
Upvote 0

sina39000

Member
WHY are you Initialize them then? Views added through the designer (and loaded by LoadLayout) do not need to get initialized again...

Comment out the line

if i don`t initialize i get this Err

 
Upvote 0

sina39000

Member
Scenario:
I Have many Labels on Designer
I want to change some properties from code by a loop and array of labels
please say to me what to do?
 
Upvote 0

mw71

Active Member
Licensed User
Longtime User
B4X:
......
    Dim lSpinner As List
    lSpinner.Initialize   
    lSpinner.AddAll(Array(Spinner1,Spinner2,Spinner1_E,Spinner2_E,spn_e_QSL_S, spn_QSL_S))
......

    For o=0 To lSpinner.Size-1   
        resetUserFontScale_Spinner(lSpinner.Get(o),varSpnSize)' varSpnSize is the new .TextSize
        'in this Sub i cach the Spinner Data, Clear, Resize and fill new the Spinner.....
    Next
......

'not testet, you must do that with your Labels
dim lbl as label
for o=0 to lSpinner.Size-1
     lbl=lSpinner.Get(o)
     lbl.TextSize=12
     .....
next

or use for each
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…