B4J Question remove created page

invocker

Active Member
hello , I need to recreate a page when it close because when I show the page again, I can see the previous contents. that mean the page not closed it Disappear

B4X:
        If FM1.IsInitialized Then
'                B4XPages.GetManager.mStackOfPageIds.Remove(B4XPages.MainPage.FM1) 'remove page2 from stack
'                B4XPages.ClosePage(B4XPages.MainPage.fm1)
'                B4XPages.MainPage.FM1 = Null
'                Dim FM1 As FM
                FM1.RecreateFM1
            End If
'            Dim FM1 As FM
             FM1.Initialize
           
            B4XPages.AddPage(str,FM1)
              B4XPages.ShowPage(str)


B4X:
public Sub RecreateFM1
    Root.RemoveAllViews
    B4XPage_Created(Root)
End Sub
the last sub work but get error when click on lv java.lang.RuntimeException: Object should first be initialized (ListView). i put the ListView in my page
 

stevel05

Expert
Licensed User
Longtime User
Without seeing the rest of the code it is difficult to help, but it looks to me like you shouldn't be initializing FM1 in line 12 or adding the page again.

But not knowing what is in B4xPage_Created(Root) it could be completely wrong.

Zip and upload the project (or an example project showing the issue) for a better answer.
 
Upvote 0

invocker

Active Member
b4xMainpage
B4X:
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region

'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip

Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Dim FM1 As FM
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
'   
    B4XPages.AddPage("FM1",FM1)
    
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Private Sub Button1_Click
     FM1.Initialize
    B4XPages.ShowPage("FM1")
End Sub
FM
B4X:
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
    Public lv As ListView
End Sub

'You can add more parameters here.
Public Sub Initialize As Object
 
    Return Me
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    'load the layout to Root
    Root.LoadLayout("LFM")
    Log(lv.Items.Size)
    If lv.Items.Size > 0 Then
        lv.Items.addAll(Array As String("7", "8","9", "10","11", "12"))
        'this values not added when show it again
    End If
    lv.Items.addAll(Array As String("1", "2","3", "4","5", "6"))
    Log(lv.Items.Size)
End Sub
Sub B4XPage_Disappear
    Log("Page  Disappear and not closed")
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

If lv.Items.Size > 0 Then
lv.Items.addAll(Array As String("7", "8","9", "10","11", "12"))

End If this values not added when show it again mean the page not closed when click closed
 
Upvote 0
Top