When do I initailize of them?

Theera

Expert
Licensed User
Longtime User
Hi all,
I need someone could explain to me about initailize(). I saw this at post#9. I can remember that Klaus told me if I built the panel on layout with the designer ,I must not initailize it. I need more knowledge.

P.S. I'm sorry,I'm not good at English.

Best Regards
Theera
 
Last edited:

Penko

Active Member
Licensed User
Longtime User
Views added with the Designer should NOT be initialized because that's done automatically.

Initialization has to do mainly with setting the correct Event for the object.

You have to initialize() items which are added dynamically, via code.

B4X:
Dim p As Panel
p.Initialize("panel")

This sets that events related to the Panel "p" have a prefix "panel".

So, if you type "panel_Click", you will catch clicking on the Panel.
 
Upvote 0

Theera

Expert
Licensed User
Longtime User
I'm lost

Hi Penko,Klaus,
Why are they different. see this #post11
 
Upvote 0

Theera

Expert
Licensed User
Longtime User
Ask some from Example

Hi Penko,Klaus,
My code is Right?
Dim lblMyLabel as Label
lblMyLabel.initialize("")
Activity.AddView(lblMyLabel, 25%x, 25%y, 50%x, 50%y)

Best Regards
Theera
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I would suggest you this code:
B4X:
Sub Globals
    Dim lblMyLabel As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    lblMyLabel.initialize("")
    Activity.AddView(lblMyLabel, 25%x, 25%y, 50%x, 50%y)
End Sub
this os OK only if you don't use a layout file and you don't want to catch any event from lblMyLabel !


If you want to catch an event from lblMyLabel you must use this code:
B4X:
Sub Globals
    Dim lblMyLabel As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    lblMyLabel.initialize("lblMyLabel")
    Activity.AddView(lblMyLabel, 25%x, 25%y, 50%x, 50%y)
End Sub

Sub lblMyLabel_Click
    ' your code for the click event
End Sub
If lblMyLabel is already in a layout file for exapmle main.bal then you should use this code:
B4X:
Sub Globals
    Dim lblMyLabel As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("main")
End Sub
Best regards.
 
Upvote 0
Top