Activity.CloseLayout?

School Boy Error

Member
Licensed User
Longtime User
Is there such as thing? I have loaded a layout when my app runs and then when the user clicks a menu item I load another layout. The problem is it's appearing over the top of the first one so you can see both. Is it possible to close a layout?

I've tried Activity.Finish but that closes the whole app!

B4X:
Sub Activity_Create(FirstTime As Boolean)

   Activity.LoadLayout("PowerZones")
   Activity.AddMenuItem("Power Zones", "PowerZones")
   Activity.AddMenuItem("Heart Zones", "HeartZones")

End Sub

Sub PowerZones_Click
   'This is where I would like to close any other layout that is loaded 

   Activity.LoadLayout("PowerZones")

End Sub

Sub HeartZones_Click
   'This is where I would like to close any other layout that is loaded
   Activity.LoadLayout("HeartZones")

End Sub
 

klaus

Expert
Licensed User
Longtime User
There is no LayoutClose function.
What you can do is:
B4X:
Sub RemoveAllViews
    Dim i As Int
    
    For Activity.NumberOfViews - 1 To 0 Step -1
        Activity.RemoveViewAt(i)
    Next
End Sub
Or add a Panel for the second layout and set the Panel.Visible property to False or True.
Or use a new Activity.

Best regards.
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
Your problem that is see both of scenes,correct?
I have experience,I created panel before for contains many objects in each scenes. And use command layout1.visiable=false : layout2.visiable=true
Best regards
Theera
 
Upvote 0

School Boy Error

Member
Licensed User
Longtime User
There is no LayoutClose function.
What you can do is:
B4X:
Sub RemoveAllViews
    Dim i As Int
    
    For Activity.NumberOfViews - 1 To 0 Step -1
        Activity.RemoveViewAt(i)
    Next
End Sub
Or add a Panel for the second layout and set the Panel.Visible property to False or True.
Or use a new Activity.

Best regards.

Klaus, I've tried this but it says

B4X:
Compiling code.                         Error
Error compiling program.
Error description: Regular variable followed by '=' expected.
Occurred on line: 119
For Activity.NumberOfViews - 1 To 0 Step -1        
Word: .
 
Upvote 0

moster67

Expert
Licensed User
Longtime User
Sorry, it must be:
B4X:
Sub RemoveAllViews
    Dim i As Int
    
    For i = Activity.NumberOfViews - 1 To 0 Step -1
        Activity.RemoveViewAt(i)
    Next
End Sub
Best regards.

Klaus you are a genius! Thanks

+1

I was going nuts and I did not want to use neither a new activity nor a panel. Thank you Klaus!
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
With this code, what if you loaded a layout file but you also created some views in code that are not part of the layout and wish to keep them. Can this code be made to remove just the views that the layout loaded? Or would it be better to just load the view in a panel and when ready, remove the panel view?

Thanks,

Margret
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Both are possible, with the panel it's somewhat easier.
But if you save the number of views on the activity just after having loaded the layout in LayoutViewNb and then add other views by code. You can remove the layout views afterwads with:
B4X:
For i = 0 To LayoutViewNb - 1
  Activity.RemoveViewAt(0)
Next
Best regards.
 
Upvote 0

cbal03

Member
Licensed User
Longtime User
When I create a layout I use a panel full screen as a container and place all views I need inside of the panel. When I want the layout to go away I say panel.removeView for the containing panel. This removes all views in the layout.
 
Upvote 0
Top