Label.Initialize problem

SPLatMan

Member
Licensed User
Longtime User
Hi, I couldn't find any existing reference to this in the forum.

I was trying a "Hello world" test program to allow me to play with the Android emulator. The program has 1 activity, with a just one Label, designed in the visual Designer. In Designer I gave it a default Text, "B4A is great".

My code is:
B4X:
'Activity module
Sub Process_Globals

End Sub

Sub Globals
   Dim Label1 As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("1")
   Label1.Initialize("Label1")   '<<<<<<<<<<<<<<<<<<<<<<<<
   Label1.Text = "Hello world"
   Activity.Invalidate 
End Sub

Sub Label1_Click
   Label1.Text = "Click!"
   Activity.Invalidate 
End Sub

My problem is that the text in the label is stuck at the design-time default. If I comment out the Label1.Initialize line, the text changes to "Hello World", but of course the Click event handler is lost.

What am I doing wrong? Why is initialising the label preventing its text from being subsequently altered?

(I can't post the project as a zip because B4A has decided it will only use a folder that I have renamed to export a zip file to ... that may require another post!)

David Stonier-Gibson
Samsung Galaxy ACE, 2.3.4
http://splatco.com
 

SPLatMan

Member
Licensed User
Longtime User
Zip/path problem resolved! Here's the full project zip (I hope).

David Stonier-Gibson
Samsung Galaxy ACE, 2.3.4
http://splatco.com
 

Attachments

  • text1-init-problem.zip
    6.1 KB · Views: 236
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
This code works.
B4X:
Sub Globals
    Dim Label1 As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
End Sub

Sub Label1_Click
    Label1.Text = "Click!"
End Sub
When you have defined a view in the Designer you should not initialize it in the code.
There is no need to reassign the Label1.Text property already set in the Designer.

Did you have a look at the Beginner's Guide ?

Best regards.
 
Upvote 0

SPLatMan

Member
Licensed User
Longtime User
Thanks Klaus.

Yes, I went through the beginner's guide, several weeks ago. Some of the concepts differ enough from VB6 to mess with my head. It's a little bit hard to remember what's needed in each set of circumstances. I should have got my clue from that fact that the compiler didn't growl at me for commenting out the .Initialize.

David Stonier-Gibson
Samsung Galaxy ACE, 2.3.4
http://splatco.com
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…