Android Question Assign values to an object named in a variable

Xakko Gris

Member
Licensed User
Hi to everybody. My firs post......

My problem is I dont know how to assign any value (i.e. a text) to an object, but this object name is in a variable (or must be in one).
In my example the objects are created in the activity (all of them), so I can't put them in any array. I can't create them in code lines, they are in specific places in the screen (each one).
When I program in VFP, I do it something like this:
a = "1" (variable in number usualy, but i do not want to convert it)
b = "lbllabel" + a + ".value" (the name of the object with the extension for attribute, ".text" in B4A)
finally, with an "&" I tell the VFP the next is an object, not a variable. Like this
&b = "any text"
So the text is assigned to the object and not to the variable "b".

How can do this en B4A? I can't make my objects by code, they are already in th activity screen, "by hand".

In my B4A example, I've got 12 labels in the screen, and i must assign the ".text" values after a SQLite query

The objects are named "lbllabel1", "lbllabel2"... til .."lbllabel12"

Regards

Xakko
 

walt61

Well-Known Member
Licensed User
Longtime User
Hi Xakko,

As you created the labels in the Designer, you could do this:

B4X:
Dim theLabels as List

theLabels.Initialize
theLabels.Add(lbllabel1)
theLabels.Add(lbllabel2)
theLabels.Add(lbllabel3)
theLabels.Add(lbllabel4)
theLabels.Add(lbllabel5)
theLabels.Add(lbllabel6)
theLabels.Add(lbllabel7)
theLabels.Add(lbllabel8)
theLabels.Add(lbllabel9)
theLabels.Add(lbllabel10)
theLabels.Add(lbllabel11)
theLabels.Add(lbllabel12)

...

Dim i as Int
Dim oneLabel as Label

For i = 0 To (theLabels.Size - 1)
   oneLabel = theLabels.Get(i)
Next

Cheers,

walt
 
Upvote 0

Xakko Gris

Member
Licensed User
Hi. Thank Walt!!
So, after that, I must assign the properties directly to oneLabel (like oneLabel.text = "....") ?
(after to take the value from the list)
Xakko
 
Upvote 0

Xakko Gris

Member
Licensed User
just for someone else who comes here, can you add a line in your the example? (like oneLabel.text = "Hello Word")

first in Globals
from initialize, in Activity_Create
last, in your process

Thanks a lot Walt!!

Xakko
 
Upvote 0
Top