Android Question array of labels

Discussion in 'Android Questions' started by sina39000, Jun 19, 2019.

  1. sina39000

    sina39000 Member

    My code:
    Code:
    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???
     
  2. DonManfred

    DonManfred Expert Licensed User

    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
     
  3. klaus

    klaus Expert Licensed 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.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

  5. sina39000

    sina39000 Member

    if i don`t initialize i get this Err

     
  6. sina39000

    sina39000 Member

  7. sina39000

    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?
     
  8. mc73

    mc73 Well-Known Member Licensed User

    Check the attached example.
     

    Attached Files:

    Erel and sina39000 like this.
  9. mw71

    mw71 Active Member Licensed User

    Code:
    ......
        
    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
     
    sina39000 likes this.
  10. sina39000

    sina39000 Member

    mc73,

    thank you so much.
    problem solved by your help.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice