Android Question B4XPages project does not change button properties

johnaaronrose

Active Member
Licensed User
Longtime User
I have a B4XPages project and am using B4A v11.20 on it. The app runs Ok on a phone except for one point. The app has a DetailsPage called by the MainPage on clicking its Start button ('defined' in the page's main.bal file. The DetailsPage has an imageview ('defined' in its details.bal file) containing a jpg photo. This photo varies according to a variable StepNumber defined in the DetailsPage and set to 1 on page creation: that works Ok. There are Previous & Next buttons defined in the details.bal. The idea is that according to StepNumber, the Enable & Visible properties should be set e.g. if the StepNumber is 1 only the Next button should be enabled & visible, if the StepNumber is in the range 2-5 both buttons should be enabled & visible, if the StepNumber is 6 only the Previous button should be enabled & visible.
Here is the relevant code from the DetailsPage:
B4X:
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
    Private lbl As B4XView
    Private iv As B4XView
    Private btnPrevious As B4XView
    Private btnNext As B4XView
    Private StepNumber 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("Details")
    StepNumber = 1
End Sub

Private Sub B4XPage_Appear
    If StepNumber < 2 Then
        btnPrevious.Enabled = False
        btnPrevious.Visible = False
    Else
        btnPrevious.Enabled = True
        btnPrevious.Visible = True
    End If
    If StepNumber > 5 Then
        btnNext.Enabled = False
        btnNext.Visible = False
    Else
        btnNext.Enabled = True
        btnNext.Visible = True
    End If
    ReloadViews
End Sub

Private Sub btnPrevious_Click
    If StepNumber > 1 Then
        StepNumber = StepNumber - 1
        ReloadViews
    End If
End Sub

Private Sub btnNext_Click
    If StepNumber < 6 Then
        StepNumber = StepNumber + 1
        ReloadViews
    End If
End Sub

I've attached a zip of the project: the whole code is approx 120 lines so I didn't think that it was worth making a Test project from it!

PS the Sub ReloadViews uses StepNumber to set the photo in DetailsPages' imageview.
 

Attachments

  • PaintingCourses.zip
    120.6 KB · Views: 186

DonManfred

Expert
Licensed User
Longtime User
You should not export as zip for B4XPages projects; use the Link in mainpage to export it.

You download it not useable.
 
Upvote 0

Spavlyuk

Active Member
Licensed User
B4XPage_Appear is only called when the page comes into view, not when the buttons are clicked.
You should move the logic from B4XPage_Appear to btnPrevious_Click/btnNext_Click.
 
Upvote 1

johnaaronrose

Active Member
Licensed User
Longtime User
B4XPage_Appear is only called when the page comes into view, not when the buttons are clicked.
You should move the logic from B4XPage_Appear to btnPrevious_Click/btnNext_Click.
It's so obvious why I was wrong when someone else points it out. I've actually moved the code to the Sub ReloadViews.
 
Upvote 0
Top