Android Question Duplicate Label with basic

antonomase

Active Member
Licensed User
Longtime User
Hi,

I'm new in Basic4Android
I have to generate a list of labels. I design one with the designer, then i want to use it to generate all the others into my program.

I write this sub :
Code: Copy
Sub DisplayLabelList (lbl0 As Label)
    Dim lblList(5) As Label
    Dim i As Int
    For i=0 To lblList.Length - 1
        lblList(i).Initialize("")
        lblList(i) = lbl0
        lblList(i).Top = i * 20
        lblList(i).Text = i
    Next
End Sub
Then I call this Sub with the lblModel designed
Code: Copy
DisplayLabelList(lblModel)
When running, I have just the last one displayed. Better, It seems that all the lblList(i) have the same values (same text and same position) and are all changed at each iteration.
How to do for having lblList(0).Top = 0 and lblList(0).Text = "0", lblList(1).Top = 20 and lblList(1).Text = "0", ... and all the others values (Left, Width, ...) same as my Model ?

Thanks
 
This line doesn't copy the label:
Code: Copy
lblList(i) = lbl0

It just assigns the same object to the variable. You should instead do something like:

Code: Copy
For i=0To lblList.Length - 1
 lblList(i).Initialize("")
 lblList(i).TextSize = lbl.TextSize
 ...

 Activity.AddView(lblList(i), i * 20, lbl.Left, Lbl.Width, Lbl.Height)
 lblList(i).Text = iNext
Next
 
Upvote 0
Another question : I can get some properties of my model, but not all
Code: Copy
lblList(i).Typeface = lbl.Typeface

But how get the Vertical Align of the model (I want all the labels in the array to be aligned on the top) ?
Or how to set the event name for all these labels (I want to click on the label and get an id set in the tag)
 
Upvote 0
Back
Top