Android Question Whenever I am trying to Load a layout within a panel with button click- White screen appears

shank_devdroid

Member
Licensed User
Longtime User
Please find below the code snippet and guide me if I am missing something here-
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private pnlHome As Panel
    Private ImageView1 As ImageView
    Private pnlLighting As Panel
    Private pnlMain As Panel
    Private pnlTempControl As Panel
    Private pnlTopBar As Panel
    Private ImageView2 As ImageView
    Private pnlTVControl As Panel
    Private pnlSTB As Panel
    Private btnRoom1 As Button
    Private pnlEntertainment As Panel
    Private btnEntertainment As Button
    Private btnLightingControl As Button
    Private btnTempControl As Button
    Private btnSecurity As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Room_Change")
    Activity.LoadLayout("Main")
    pnlHome.LoadLayout("Home")
    pnlLighting.LoadLayout("Lighting")
    pnlTempControl.LoadLayout("Temperature_Control")
    pnlEntertainment.LoadLayout("Entertainment")
   
    pnlMain.Visible=True   
    ImageView2.Visible=True
    pnlHome.Visible=False
    pnlLighting.Visible=False
    pnlTempControl.Visible=False
   
   
   

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
    ExitApplication
End Sub


Sub btnRoom1_Click
    'Activity.LoadLayout("Home")
    pnlHome.LoadLayout("Home")
    btnLightingControl.SetBackgroundImage(LoadBitmap(File.DirAssets,"lighting.png"))
    btnTempControl.SetBackgroundImage(LoadBitmap(File.DirAssets,"temp.png"))
    btnEntertainment.SetBackgroundImage(LoadBitmap(File.DirAssets,"music-entertainment-psd-icon.png"))
    btnSecurity.SetBackgroundImage(LoadBitmap(File.DirAssets,"security.png"))
   
    pnlHome.Visible=True
    pnlMain.Visible=False
    pnlLighting.Visible=False
    pnlTempControl.Visible=False
    pnlEntertainment.Visible=False
   
End Sub
Sub btnEntertainment_Click
    pnlEntertainment.LoadLayout("Entertainment")
    pnlEntertainment.Visible=True
    pnlMain.Visible=False
    pnlHome.Visible=False
    pnlLighting.Visible=False
    pnlTempControl.Visible=False
End Sub
Screenshot_2015-08-25-12-53-26.png
Screenshot_2015-08-25-12-53-26.png
Screenshot_2015-08-25-12-53-38.png
 

shank_devdroid

Member
Licensed User
Longtime User
Thanks for the reply!
The pnlHome and pnlEntertainment are children of the activity.
Whenever I try clicking the living room button i.e the Room1 button the white screen appears.
I will try the bringtofront command but is this a work around or the only best solution?
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
If you have 2 (or more) panels that are child of another panel then if you want to show panel1 that could be behind panel2, you need to bring it to the front this is not a work around.

I see in your code that you hide all other panels but maybe you missed one and brintofront can solve it.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Btw you dont need to load every time the layout to that panel. On activity create (that will be raised on EVERY app start) its enough to load the layout, so in button click event just write visible = true and bringtofront..

Good luck :)
 
Upvote 0
Top