Types
The above code could also be written more elegantly:B4X:Sub Globals Dim Btn1, Btn2, Btn3 As Button End Sub Sub Activity_Create(FirstTime As Boolean) Btn1.Initialize("Btn") Btn2.Initialize("Btn") Btn3.Initialize("Btn") Activity.AddView(Btn1, 10dip, 10dip, 200dip, 50dip) Activity.AddView(Btn2, 10dip, 70dip, 200dip, 50dip) Activity.AddView(Btn3, 10dip, 130dip, 200dip, 50dip) End Sub Sub Btn_Click Dim b As Button b = Sender 'Cast the Object to Button b.Color = Colors.RGB(Rnd(0, 255), Rnd(0, 255), Rnd(0, 255)) End Sub
.B4X:Sub Globals End Sub Sub Activity_Create(FirstTime As Boolean) For i = 0 To 9 'create 10 buttons Dim Btn As Button Btn.Initialize("Btn") Activity.AddView(Btn, 10dip, 10dip + 60dip * i, 200dip, 50dip) Next End Sub Sub Btn_Click Dim b As Button b = Sender b.Color = Colors.RGB(Rnd(0, 255), Rnd(0, 255), Rnd(0, 255)) End Sub
Can I do the above to a Label control?
B4X:
Sub GlobalsEnd SubSub Activity_Create(FirstTime As Boolean)
For i = 0 To 9 'create 10 Labels
Dim Lbl As Label
Lbl.Initialize("Lbl")
Activity.AddView(Lbl, 10dip, 10dip + 60dip * i, 200dip, 50dip)
Lbl.textcolor = colors.back
next
Lbl(1).text = "TEST"
end sub
I can not get the above code working?
Thanks for any Help.