Android Question Changing label text programmatically on another page

this is the code on page 2 which i have publicly declared the Integer Iam trying to copy to page 3, unsuccessfully.
I have spent hours researching this and tried many examples and am unable to get any examples to work which is on my abilities totally.

Page 1 code - var iam trying to send to page 3 [ DiffToCopyToSuggestedReadings ]

B4X:
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
'    Private Activity As Activity
    Private FNumberTxt As EditText
    Private rNumberTxt As EditText
    Private DiffTxt As EditText
    Private OADistanceTxt As EditText
    
    Private ToeQtyLbl As Label
    Private OADistanceLbl As Label
    
    Private OverAllDistance As Double   
    Private BtnSuggReading As Button
    
    Public dDifference As Int
    
    Public DiffToCopyToSuggestedReadings As Int
    
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("LeftSide")           
'    Page3.Initialize
'      B4XPages.AddPage("page 3", Page3)
'    B4XPages.AddPageandcreate("page 3", Page3)
'    B4XPages.AddPageandcreate("SuggestedReadings", Page3)
'    Dim p As SuggestedReadings = B4XPages.GetPage("page 3")
'    B4XPages.ShowPage("page 3")
    
End Sub
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Private Sub GetDiffBtn_Click
    DiffTxt.Visible=True
    ToeQtyLbl.Visible=True
        
    Dim fFrontNumber As Int =  FNumberTxt.Text
    Dim rRearNumber As Int =  rNumberTxt.Text
'    Dim dDifference As Int= fFrontNumber - rRearNumber   
     dDifference = fFrontNumber - rRearNumber
    DiffTxt.Text = dDifference
    
    DiffToCopyToSuggestedReadings = dDifference
            
    OverAllDistance  = OADistanceTxt.text       
    Dim tToe As Double  = dDifference / OverAllDistance
    tToe = Round2(tToe, 1)
        
    If FNumberTxt.Text > rNumberTxt.Text Then
        ToeQtyLbl.text = tToe & "mm per meter to the right"       
        Else
        ToeQtyLbl.text = tToe & "mm per meter to the left"
    End If
    

    'save difference to SuggestedReadings page
    
'    save difference mm to SuggestedReadings page

'    MsgboxAsync(dDifference,"difference")   
End Sub


Private Sub BtnSuggReading_Click   
    
    B4XPages.ShowPage("SuggestedReadings")
End Sub

page 2 code

Sub Class_Globals
Private Root As B4XView 'ignore
Private xui As XUI 'ignore
Private LblCurrentDiff As Label
Public LblDiff As Label
' Private leftside As B4XPageInfo

' Private Difference As B4XView

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("SuggestedReadings")

' LblDiff.Text = LeftSide.Difference



LblDiff.Text = DiffToCopyToSuggestedReadings


End Sub
B4X:
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
    Private LblCurrentDiff As Label
    Public LblDiff As Label
'    Private leftside As B4XPageInfo

'    Private Difference As B4XView
    
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("SuggestedReadings")
    
'    LblDiff.Text = LeftSide.Difference



    LblDiff.Text = DiffToCopyToSuggestedReadings
    
    
End Sub
 

Attachments

  • AlignmentAdjustments.zip
    21.1 KB · Views: 11

aeric

Expert
Licensed User
Longtime User
Each B4XPage has an Id.

The code in Page 3 (SuggestedReadings) is as follow:

B4X:
Private Page2 As LeftSide

B4X:
Page2 = B4XPages.GetPage("LeftSide")
LblDiff.Text = Page2.DiffToCopyToSuggestedReadings

Edit: I was first replying without checking the project. After checking, I found the Public variable is declared in Page2 instead of Page1 so have updated the code accordingly.
 
Last edited:
Upvote 0
Top