Android Question Returning from page 2 and doing something immediately

Steve-h

Member
Using B4XPages I have a main page layout and a Page2 layout.

I use “B4XPages.ShowPage ("Page2")” to move to page 2 and then “B4XPages.ShowPage ("MainPage")” to come back. As a result of some user input on page 2 I want to immediately change the visibility of some items and alter some text. How can I do that immediately without an event to respond to ?

The only solution I have come up with is to set a timer running before leaving MainPage which occurs as an event when I return. Plainly there must be a better way. If I could somehow return directly to the sub from which I said “B4XPages.ShowPage ("Page2")” I would understand where I was.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I'm not sure that I understand, however I'm sure that a timer is not needed.

immediately change the visibility of some items and alter some text. How can I do that immediately without an event to respond to ?
B4X:
B4XPages.ShowPage ("MainPage")
B4XPage.MainPage.EditText17.Text = "whatever you like"
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
Just in case Erel has not quite understood your question, here is another suggestion.

Why don't you use the MainPage_Appear event instead of the timer event? You can set a global switch in Page2 if the user makes a critical input and check the switch whenever the main page appears.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
you can call the sub that is on mainpage from page2 before you call "B4XPages.ShowPage ("MainPage")"

so basically something like this:

B4X:
Private Sub Button1_Click
    B4XPages.GetPage("mainpage").As(B4XMainPage).loadData 'this sub is a Public sub in mainpage'
    B4XPages.ShowPage("MainPage")"
End sub
 
Upvote 0

Steve-h

Member
Thank you for the replies, the help is appreciated. I probably confused the issue by not explaining the question well enough.

Ilan gets closest, as I understand it his solution allows me to call a PublicSub on MainPage where I can alter the visibility of some controls and text in labels before retuning and then calling main page itself. I will experiment with that approach.

My confusion probably comes from not really understanding what I am doing when switching pages using :-

B4XPages.ShowPage ("Page2") to call Page2
and
B4XPages.ShowPage ("MainPage") to return to MainPage

logging shows that it never seems to return to the sub on MainPage that called Page2 yet it does end up back on MainPage and seems to run the code on MainPage.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
My confusion probably comes from not really understanding what I am doing when switching pages using :-

B4XPages.ShowPage ("Page2") to call Page2
and
B4XPages.ShowPage ("MainPage") to return to MainPage

imaging you have 2 panels in your activity. 1 is called MainPage and the second is called Page2.

by calling B4XPages.ShowPage ("Page2") you hide panel 1 that is the MainPage and show panel 2 that is Page 2
and the rest should be already clear
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
btw i prefer to use on mobile apps

B4X:
B4XPages.ShowPageAndRemovePreviousPages("mainpage")

this will show the next page and remove the page that it was called from.
 
Last edited:
Upvote 0

Steve-h

Member
The explanation that calling the page simply hides the other was very helpful, I was thinking of it as calling a sub from which you had to return .

Thank you.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…