B4J Question How to refresh a page when using B4XPages

mcorbeel

Active Member
Licensed User
Longtime User
I just began with the B4XPages and I must say that this is a huge improvement. I like it. But i am facing an issue with refreshing data on another page. I always get the message that the object is not initialized. It's obvious that I am doing someting basic wrong. Can someone put me on the right track here? I made a small project that you can open with B4J to show the issue... Thank you!
 

Attachments

  • B4xPagesTest.zip
    198.9 KB · Views: 129

klaus

Expert
Licensed User
Longtime User
You should move these two lines from GotoNext to B4XPage_Created.
B4X:
    Page_Result.Initialize
    B4XPages.AddPage("Page_Result", Page_Result)
In your case, you create a new page each time you click on a Button.
You should initialize the Page only once!
 
Upvote 0

mcorbeel

Active Member
Licensed User
Longtime User
Just tried this and it works.
I put the Root view of the result page in a global variable. But is this the best way of doing it?

B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Log("Page_Result B4XPage_Created")
    'declared variable "ResultView" in main module
    Main.ResultView = Root1
End Sub

private Sub B4XPage_Appear()
    Main.ResultView.RemoveAllViews
   
    Label.Initialize("Label")
    Main.ResultView .AddView(Label, 20dip, 20dip, 200dip, 40dip)
   
    Label.Text = "You clicked button " & Main.ButtonClicked
End Sub
 
Upvote 0

mcorbeel

Active Member
Licensed User
Longtime User
You should move these two lines from GotoNext to B4XPage_Created.
B4X:
    Page_Result.Initialize
    B4XPages.AddPage("Page_Result", Page_Result)
In your case, you create a new page each time you click on a Button.
You should initialize the Page only once!
Indeed Klaus, that did the trick. Thank you for your help!
 
Upvote 0
Top