Android Question A simple Matrix control...

Spectre

Active Member
Licensed User
Longtime User
Hi!
It is possible to create a control array as was the case in VB?


B4X:
For i= 0 to 50
    label1(i).text="Number" & i
next

Best regards, spectre....
 

DonManfred

Expert
Licensed User
Longtime User
I´m not sure if i understand correctly what you want. Maybe you should explain more details.

You can for sure have an array of objects. You also can do all in code.

Maybe the results to Quiz #10 help you finding an example?

PS: BTW, welcome to the B4A-Community!
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Yes and no.
It is not exactly the same as in VB.
You cannot define an array of views in the designer.
But you can define one in the code.
Dim lbl(10) As Label works.
Then it depends if your Labels are part of a layout file or if you add them in the code.
in the code you can do it like this:
B4X:
For i = 0 to 9
    lbl(i).Initialize("lbl")
    lbl(i).Text = ????
    lbl(i).Tag = i
Next
If you have ten Labels defined in the designer you can set the Labels from the Designer to the Label Array by:
lbl = Array As Label(Label1, Lablel2, Lablel3...)
 
Upvote 0

Spectre

Active Member
Licensed User
Longtime User
B4X:
Sub Globals

Dim Maylab (12) As Label
Dim sv2d As ScrollView2D
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Dim i As Int

For i = 0 To 9
Dim lbl As Label
    lbl.Initialize("Maylab")
    Maylab(i).Text = "NO WP"
    Maylab(i).Tag = i
Next
  
    sv2d.Initialize(1000dip, 1200dip, "sv2d")
  
  
    Maylab(0).TextSize=20
    sv2d.Panel.AddView(Maylab(0),1dip , 130dip, 400dip, 80dip)
      
      
    Activity.AddView(sv2d, 0,200dip, 400dip, 900dip)
    sv2d.Panel.Width = sv2d.Width

I guess I did not understand ...
 
Upvote 0

Spectre

Active Member
Licensed User
Longtime User
hi! Klaus...
the problem that presents itself to me, however, is that if I put the text eg "no wp" in the label I get an exception and crashes ..
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
  sv2d.Initialize(400dip, 10*50dip, "sv2d")
   
    For i = 0 To 9
        Dim lbl As Label
      lbl.Initialize("Maylab")
    lbl.Text = "NO WP #"&i
        lbl.Tag = i
      lbl.TextSize=14
        If i = 0 Then
          lbl.TextSize=32
            lbl.Color = Colors.Red
        End If
        Maylab(i) = lbl
      sv2d.Panel.AddView(Maylab(i),1dip ,i*50dip, 400dip, 50dip)
    Next
 
  'Maylab(0).TextSize=20
   
    Activity.AddView(sv2d, 0,50dip, 100%x, 100%y-50dip)
 
Upvote 0

Knoppi

Active Member
Licensed User
Longtime User
Hello Spectre,

try this code:
B4X:
Sub Globals
    Dim Maylab (12) As Label
    Dim sv2d As ScrollView2D
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Dim i As Int

    sv2d.Initialize(1000dip, 1200dip, "sv2d")

    For i = 0 To 9
        Maylab(i).Initialize("Maylab")
        Maylab(i).Text = "NO WP"
        Maylab(i).Tag = i
        Maylab(i).TextSize=20
        sv2d.Panel.AddView(Maylab(i),1dip , i * 90dip, 400dip, 80dip)
    Next
     
    Activity.AddView(sv2d, 0, 10dip, 400dip, 900dip)
End Sub

Sub Maylab_Click
    Dim lbl As Label
    lbl=Sender
    ToastMessageShow( "Label No: " & lbl.Tag, False)
End Sub

Knoppi
 
Upvote 0
Top