Android Question display text in label view using an array

rene castanos

New Member
hi. first of all i'd like to say thank you to Erel for being patient with me.

i'm just trying to display some letters using Label1.Text = "A" up to Label12.Text = "L" which comes out fine. i can see the output on my phone with all the letters A to L lined up across the screen. now i'm trying to 'shorten' the code using an array like this:

dim mlabel(12) as label

for i = 0 to 11
mlabel(i).initialize(" ")
mlabel(i).text = letters(i)
next

i got these ideas from all the questions in this forum. i'm even trying to apply the principle behind the buttons in the chapter 3 second program, beginner's guide. i still can't understand most of the codes but i'm trying.

the letters(i) variable holds the letters A to L. the code compiles fine. it's just that when i launch the app on my phone the screen is blank. everything is default here with the labels. i just can't connect the mlabel(i) to the actual Label1.Text view. if i do it the 'long' way of coding all the text into the label views one by one the letters will show on my phone. but if i do the array version nothing happens.

i just started last month and i'm pretty impressed with this software since i don't know anything about java and android. so thanks to the guys who developed B4A.

everyone's help is highly appreciated. thanks!

rene
 

klaus

Expert
Licensed User
Longtime User
Use this:
B4X:
Dim mlabel(12) As Label
mlabel = Array As Label (Label1, Label2, Label3, Label4, Label5, Label6, Label7, Label8, Label9, Label10, Label11, Label12)
For i = 0 to 11
    mlabel(i).Text = letters(i)
Next
 
Last edited:
Upvote 0

rene castanos

New Member
thanks for the reply Klaus!

i've already used this sample of yours from one of your replies in the forum and i still can't make it work. still nothing. still confused, sorry.

i'm sending you what i'm doing at the moment the actual code. please forgive me for my programming style.

thanks in advance.

rene
 

Attachments

  • taplabel.zip
    337.2 KB · Views: 295
Upvote 0

Mrjoey

Active Member
Licensed User
Longtime User
mlabel(i).initialize("mlabel")
B4X:
sub mlabel_click
dim lbl as label
lbl = sender
lbl.text = "whatever u want"

end sub
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
i've already used this sample of yours from one of your replies in the forum and i still can't make it work. still nothing. still confused, sorry.
You have not looked carefully at my code in post #2, there is no mlabel(i).initialize(" ") nor mlabel(i).initialize("mLabel").

- As you want to use the Labels you defined in the Designer, you must NOT initialize the Labels in the For / Next loop !
- You must define the labels in mlabel = Array As Label (Label0, ... with the names you defined in the Designer.
- For the Label color you must set, in the Designer, the Alpha value to 255 to see the color, by default it's 0 (transparent).

Attached your updated project.
 

Attachments

  • taplabel_1.zip
    7.7 KB · Views: 291
Upvote 0

rene castanos

New Member
to Klaus,

thank you very much for the updated code u sent me. i do apologize for my ignorance here. you can be sure that i'll definitely look carefully next time. i really appreciate your help.

i ran your code and it left me awed, amazed actually, and happy. i'm now wishing i want to have the same logical thinking you guys have (sigh). but thanks!

to Mrjoey,

thank you for your reply. you gave me an idea with your code. it will surely come in handy!

Thanks for all the support! i'll be back (very satisfied).
 
Upvote 0
Top