Android Question More Labels with same attributes

Tomas Petrus

Active Member
Licensed User
Longtime User
Hi,

I have more labels in one panel and I need to give them same Background, TextColor, TextSize etc. Is there any easier way to do that than write it over and over again?

B4X:
  Label1.TextColor = Colors.Black
  Label1.Gravity = Gravity.CENTER_VERTICAL

  Label2.TextColor = Colors.Black
  Label2.Gravity = Gravity.CENTER_VERTICAL

  Label3.TextColor = Colors.Black
  Label3.Gravity = Gravity.CENTER_VERTICAL

.
.
.
.

Thanks for answer
 

eurojam

Well-Known Member
Licensed User
Longtime User
it works like this...
B4X:
Dim Label1(10) As Label
For i = 0 To 9
    Label1(i).TextColor = Colors.Black
    Label1(i).Gravity = Gravity.CENTER_VERTICAL
Next
 
Upvote 0

Tomas Petrus

Active Member
Licensed User
Longtime User
Thanks, but I can't use it. I need to have specific name and text for each Label and some times it is skipped because of empty value in database
 
Upvote 0

eurojam

Well-Known Member
Licensed User
Longtime User
then you can put them explicit into an array or list like this:
B4X:
Dim labels() As Label 
labels= Array As Label (label1,  label2,  label3,  label4)
For i = 0 To labels.size-1
    labels(i).TextColor = Colors.Black
    labels(i).Gravity = Gravity.CENTER_VERTICAL
Next
 
Upvote 0
Top