Android Question Layout Unload Problem

Sreenadh OG

Member
Licensed User
Hai all,
I have a program with three layout, Main page contain three button. I want to unload each layout at particular Button_click, My code given below

Sub button2_click
Activity.LoadLayout ("layout2")
End Sub

Sub button1_click
(code to unload layout3 here???)
(code to unload layout2 here???)
Activity.LoadLayout ("layout1")

End Sub
Sub button3_click
(code to unload layout2 here???)
(code to unload layout1 here???)

Activity.LoadLayout ("layout3")
End Sub
 

LucaMs

Expert
Licensed User
You can try using Activity.RemoveAllViews before loading another layout.
(I do not know if this will work).

However, it is likely that you're trying to get something in a twisted way.
Probably you should use more Activities or, at least, more Panels (loading the layouts in them and displaying them when necessary).
 
Upvote 0

Sreenadh OG

Member
Licensed User
But, I have HorizontalScrollView with many Button, after the use of Activity.RemoveAllViews i got following problem

This is my code for main Layout:
B4X:
Activity.LoadLayout("Main") 
itemSize = HsvMain.Width / 3
    HsvMain.Panel.Width = itemSize * 7
        Table = HsvMain.Panel
        Dim p As Panel
        p.Initialize("")
        p.Color = Rnd(0x90000000, -1)
        BtnHome.RemoveView
        BtnListing.RemoveView
        BtnConfig.RemoveView
        BtnAddBk.RemoveView
        BtnSearch.RemoveView
        BtnProfile.RemoveView
        BtnLogut.RemoveView
        BmpHome.Initialize(File.DirAssets,"Home.png")
        BtnHome.SetBackgroundImage(BmpHome) 
        HsvMain.Panel.AddView(BtnHome, itemSize*0, 0, itemSize, HsvMain.Panel.Height)
        HsvMain.Panel.AddView(BtnListing, itemSize*1, 0, itemSize, HsvMain.Panel.Height)
        HsvMain.Panel.AddView(BtnConfig, itemSize*2, 0, itemSize, HsvMain.Panel.Height)
        HsvMain.Panel.AddView(BtnAddBk, itemSize*3, 0, itemSize, HsvMain.Panel.Height)
        HsvMain.Panel.AddView(BtnSearch, itemSize*4, 0, itemSize, HsvMain.Panel.Height)
        HsvMain.Panel.AddView(BtnProfile, itemSize*5, 0, itemSize, HsvMain.Panel.Height)       
        HsvMain.Panel.AddView(BtnLogut, itemSize*6, 0, itemSize, HsvMain.Panel.Height)


B4X:
'Load Next Layout
Sub btnSearch_click
Activity.LoadLayout ("Search")
'This Layout contain many views
End Sub
img.JPG




B4X:
'Now i want to load Main layout again
Sub BtnMain_click
Activity.RemoveAllViews
Activity.LoadLayout("Main")
End Sub

Now i am getting Design problem like this..
imgnew.JPG
 
Upvote 0

klaus

Expert
Licensed User
You should use different Activities instead of removing and reloading layouts, thats the standard way Android works.
Or you could use Panels with the layouts and handle their Visible property.
 
Upvote 0

Sreenadh OG

Member
Licensed User
Thank u, I solved the problem with Panel...My code is..
B4X:
panel1.Initialize("")
panel1.LoadLayout("Main")
Activity.AddView(panel1, 0, 0, 100%x, 100%y)
Initialize
 
Upvote 0
Top