In B4A, when changing any parameter (for example, font size), I did it like this:
Activity.Finish
StartActivity(Me)
The newly opened Activity is loaded with the new parameter.
How can this be done with B4XPage?
You can achieve a similar effect in B4XPages by calling B4XPages.ClosePage followed by B4XPages.ShowPage. However, instead of restarting the page entirely, it's more efficient to update the parameter directly and then call a method like UpdateUI on the current page to reflect the changes (like font size). This avoids unnecessary overhead and gives a smoother user experience. If needed, you can also use B4XPages.MainPage to access shared methods or data between pages.
When you use B4XPages the state of the views on the pages are kept.
If you switch to another page and then back the views settings of the page are reused.
The font size for instance is the same as before the switch.
You should try it out with a test project.
There is no point in continuing. You did not answer the question, and for some reason you did not provide the B4XPages code, even if you knew how to solve the problem. That's it, I put a period.
I deliberately called the create method because it's not just a matter of rereading the layout but of completely reloading the page, with all the parameters etc.
I deliberately called the create method because it's not just a matter of rereading the layout but of completely reloading the page, with all the parameters etc.
For example, it's common practice (not good, I'd say) to initialize pages (B4XPages) and add them to the collection in B4XPage_Created.
This operation should only be performed once.
In fact, I wrote that it is not an elegant solution, but it works, it was to respond to post no. 1 in which it reported how to obtain the same result as closing an activity and reopening it with b4xpages, something I would never do because I would implement an UpdateUi with the modification of the parameters.
valerioup, your example works.
In my case, after rebooting, I need to set a new font size in B4XComboBox, while preserving its contents.
Taking into account LucaMs comment, tell me how to implement UpdateUi?
I attached the example. I commented out the code that I don't like.
Private Sub Button1_Click
' B4XComboBox1.cmbBox.Clear
' B4XComboBox1.SetItems(lst)
' B4XComboBox1.SelectedIndex=1
' B4XComboBox1.cmbBox.TextSize=14
' Root.RemoveAllViews
' B4XPage_Created(Root)
' B4XComboBox1.cmbBox.TextSize=14
UpdateUI
End Sub
Sub UpdateUI
IteraTutteLeView
'Imposta i caratteri
B4XComboBox1.cmbBox.TextSize=14
Spinner1.TextSize=14
End Sub
Sub IteraTutteLeView
For Each v As B4XView In Root.GetAllViewsRecursive
'Log($"View: ${v} - Tipo: ${v.Tag}"$)
If v Is Button Then
'non cambio nulla
Else
' Esempio: se vuoi fare qualcosa su tutti i bottoni
If v Is Label Then
'Dim lab As Label = v
'test con cambio colore
v.TextColor=Colors.Red
v.TextSize=14
End If
End If
Next
End Sub
Unfortunately, the spinner doesn't allow you to change the font size directly, but by iterating on the page components you can simply change the font (I added the red color only to make the screen update visible). This is an alternative approach but it works for your case.
Thanks to everyone for participating and advice!
Reloading the page is not required yet due to the solution found for changing the font size of B4XComboBox.
B4X:
Private Sub Button1_Click
For Each v As B4XView In Root.GetAllViewsRecursive
If v Is Button Then
Else If v.Tag Is B4XComboBox Then
Dim cmb As B4XComboBox=v.Tag
cmb.cmbBox.TextSize=14
Else if v Is Label Then
v.TextSize=14
End If
Next
End Sub