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

Arf

Well-Known Member
Licensed User
Longtime 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.
 

DonManfred

Expert
Licensed User
Longtime User
make sure you did not name the object the same
name objects created in code other than objects created in a layout.

For more hints i need to see more code
 
Upvote 0

Arf

Well-Known Member
Licensed User
Longtime 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?
 
Upvote 0

keirS

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

stevel05

Expert
Licensed User
Longtime 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.
 
Upvote 0

Fusseldieb

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

James Chamblin

Active Member
Licensed User
Longtime 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

  • SplashScreen.zip
    8.6 KB · Views: 149
Upvote 0
Top