Android Question How to clear old view in panel

nickysuwandi

Member
Licensed User
Longtime User
Dear All

I have create 1 panel to load layout page base on user click (layout Home, Notif and History).
Each layout have some Lable,Button, B4XFloatTextField, SwiftButton .
My problem is, when i have load layout Notif and back to layout Home. When we click some area, the button in layout Notif still working . So how to clear layout Notif in panel, before i load new Layout (layout home) over it?

Thanks

Nicky


example:
Private Sub lblhome_Click
    Pnlmenuhold.Addview(CreateListItemPage("pghome",Pnlmenuhold.Width, Pnlmenuhold.Height+50 ),0,0,Pnlmenuhold.Width,Pnlmenuhold.Height)
End Sub

Private Sub lblnotif_Click
    Pnlmenuhold.Addview(CreateListItemPage("pgnotif",Pnlmenuhold.Width, Pnlmenuhold.Height+50 ),0,0,Pnlmenuhold.Width,Pnlmenuhold.Height)
End Sub

Private Sub lblhistory_Click
    Pnlmenuhold.Addview(CreateListItemPage("pghistory",Pnlmenuhold.Width, Pnlmenuhold.Height+50 ),0,0,Pnlmenuhold.Width,Pnlmenuhold.Height)
End Sub

Sub CreateListItemPage(namapage As String ,Width As Int, Height As Int) As Panel
    Dim p As Panel
    p.Initialize("")
    Root.AddView(p ,0,0,  Width, Height)
    p.LoadLayout(namapage)
    p.RemoveView
    Return p
End Sub
 

zed

Active Member
Licensed User
Maybe like this
ex:
Sub CreateListItemPage(namapage As String ,Width As Int, Height As Int) As Panel
    if p.IsInitialized then p.RemoveAllNodes
    
    Dim p As Panel
    p.Initialize("")
    ---
    ---
 
Upvote 0

nickysuwandi

Member
Licensed User
Longtime User
Thanks Zed, this code cause error " Undeclared variable p"


I think this cause because i have upgrade B4A to version 12.50, when using old version i have no problem (version 11.xx).

i have try create some layout, make some button and put panel overwrite (upside) then button,i can still can click the button (is this bug or i have miss some step?).

Thanks
 
Upvote 0

PaulMeuris

Active Member
Licensed User
If the "Pnlmenuhold" panel can only contain 1 ListItemPage panel at a time then you could put this highlighted line 2 before the Pnlmenuhold.Addview line in each subroutine:
B4X:
Private Sub lblhome_Click
    Pnlmenuhold.RemoveAllViews
    Pnlmenuhold.Addview(CreateListItemPage("pghome",Pnlmenuhold.Width, Pnlmenuhold.Height+50 ),0,0,Pnlmenuhold.Width,Pnlmenuhold.Height)
End Sub
You are using a B4A panel, right?
 
Upvote 0

nickysuwandi

Member
Licensed User
Longtime User
Thanks PaulMeuris, i had using this code before, this make all my view removed not only in Pnlmenuhold
 
Upvote 0

PaulMeuris

Active Member
Licensed User
this make all my view removed not only in Pnlmenuhold
The method RemoveAllViews does remove all the views from the Pnlmenuhold.
Can you explain what you try to do with this code:
B4X:
    Root.AddView(p ,0,0,  Width, Height)
    p.LoadLayout(namapage)
    p.RemoveView
Or better yet, can you attach your project so that we can test it better?
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
A simple and practical way is to create overlapping panels, one for each activity (not Android activitiy, obviously, phase) and make only one of them visible at a time.
So you could have a pnlNotif, another pnlHome, load their respective layouts into them and simply set the visibility of them.
 
Upvote 0

nickysuwandi

Member
Licensed User
Longtime User
LucaMS thanks for you suggestion, i had set inactive panel to visible=False, this solve my problem ? ?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…