Android Question How can I tell if a layout is loaded?

Arf

Well-Known Member
Licensed User
I've got a label that I initialize in my main layout screen, however since adding a splash screen, I get a 'label should be initialised first' error when I try set it to something on Activty_Resume.

This is obviously happening when the splash screen is up and the main screen doesn't exist yet. So how can I check that the layout to what that label belongs, is in fact loaded up before I set the label text?

I know I'm going to kick myself when I hear the answer!

Thanks.
 

Arf

Well-Known Member
Licensed User
Well Label1 is a label in "MainLayout.bal", I clicked 'generate members' and Dim Label1 As Label got added to my main activity.

In my main activity, in Activity_Resume, I have:
Label1.Text = "blah di blah"

And thats where I get the error.

When the main activity starts, the first layout that gets loaded is "Splash.bal", which is the splash screen which is then removed by a timer after 3 seconds, and "MainLayout.bal" then gets loaded up.

I think sometimes in Activity_resume, I'm trying to set Label1.text when "MainLayout.bal" is not the active screen layout. - Is this most likely the problem or should that not matter?
 

keirS

Well-Known Member
Licensed User
If MainLayout.bal has not been loaded then Label1 will not be initialized so you will get an error.
 

stevel05

Expert
Licensed User
The easiest way to check would be to test Label1 to see if it's initialized: If Label1.IsInitialized. If it is then the layout is loaded.

You could use it in your Resume sub: If Label1.IsInitialized then Label1.Text = "Whatever" just in case it resumes with a different layout.
 

Fusseldieb

Active Member
Licensed User
Use
B4X:
If Label1.IsInitialized=True Then
Label1.Text="Loaded"
Else
Msgbox("Label not loaded!!","Error")
End If
 
  • Like
Reactions: Arf

James Chamblin

Active Member
Licensed User
I'm thinking it may be better to load your main layout first, then create a panel to cover the entire activity and load your splash screen there. You can then remove the splash screen panel after 3 seconds.
 

Attachments

Top