Android Question [Solved]Assign an array of views in declaration

Martincg

Member
Licensed User
Longtime User
I wanted to get a layout approximately correct using the designer. I have 5 sets of views in one area.
I wanted to set the layout correctly in code.
so I did this
B4X:
Private arDay() As Label = Array As Label(lblDay0, lblDay1, lblDay2, lblDay3, lblDay4)

But I found I had to do this
B4X:
Private arDay(5) As Label

'then
 arDay(0)initialize("")
arDay(0) = lblDay0


which partly defeats my plan.
Obviously I can add the labels and other views programmatically, but is there a way to assign arrays of views in a declaration?
 

klaus

Expert
Licensed User
Longtime User
If you have lblDay0, lblDay1, lblDay2, lblDay3, lblDay4 in a layout and you load it, no need to Initialize the Labels.

The code below works:
B4X:
Sub Globals
    Private lblDay(), lblDay0, lblDay1, lblDay2, lblDay3, lblDay4 As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Main")
    lblDay = Array As Label (lblDay0, lblDay1, lblDay2, lblDay3, lblDay4)
   
    For i = 0 To lblDay.Length - 1
        lblDay(i).Text = "Test " & i
    Next
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…