iOS Question B4XPages - run a sub on .ShowPage

luke2012

Well-Known Member
Licensed User
Longtime User
Hi all,
I'm using B4XPages framework (by @Erel) and I have two pages: PageA and PageB (for example). Within PageA, when a user click on a clvList item I run "B4XPages.ShowPage("PageB").

Before PageB is displayed to the user I need to run a sub defined within PageB.
How to do this ?

Thanks in advance for your suggestions :)
Luca.
 

luke2012

Well-Known Member
Licensed User
Longtime User
Make the B4XPage definition public in the MainPage and access it like on a class.

Hi Alexander,
the sub that I need to call is already public (Public Sub LoadCard):

B4X:
'PageA
Sub Class_Globals

    Sub clvCardList_ItemClick (Index As Int, Value As Object)
        #if B4A 'This works fine only for Android version
            PageB.LoadCard (AppGlobals.CardFullContent)
        #End If
    End Sub

End Sub

'PageB
Sub Class_Globals

Public Sub LoadCard (CardFullContent As Map)
'......
End sub

Sub [B]B4XPage_Resize[/B] (Width As Int, Height As Int)

'- This work fine within B4i but it is called only one time (only when page resize)
'- I need to call each time the user click on a item to load the corresponding item data
'The issue now is that the displayed data ins't refreshed if the item changes (PageA - clvCardList_ItemClick)

LoadCard (AppGlobals.CardFullContent)

End Sub

End Sub

it already calls it within a sub of the PageA class (page). Page.LoadCard () and this works fine in B4A (Android).

In B4i I should call LoadCard () every time the PageB page is .Show () is called from the (sub) _ItemClick event contained within the PageA.

So, in my opinion, it should be the same page (PageB) that triggers the sub LoadCard () it contains every time it is viewed via .Show.

I hope I have been able to explain myself well.
 
Upvote 0

luke2012

Well-Known Member
Licensed User
Longtime User
and if you use the b4xpage appear event?
B4X:
Subs within PageB....

Private Sub CreateItem (cfv As CardFullValue) As B4XView

    Private pnl As B4XView = xui.CreatePanel("")
    pnl.SetLayoutAnimated (0,0,0,100%x, 100%y)
    pnl.LoadLayout("CardFull_itemlayout")

    Return pnl

End Sub

Public Sub LoadCard (CardFullContent As Map)

    clvCardFull.Clear
    'Create Card item and populate it with all the card fields
    Private CardFullVal As CardFullValue 
    CardFullVal.Title = CardFullContent.Get(AppGlobals.FIELD_CARD_TITLE)
    Private pnl As B4XView = CreateItem (CardFullVal)
    clvCardFull.Add(pnl, CardFullVal)
    clvCardFull.sv.ScrollViewOffsetY = 0

End Sub

Private Sub B4XPage_Appear
    Log("EVENT - BusinessCard::B4XPage_Appear")
    LoadCard (AppGlobals.CardFullContent)
End Sub

Sub B4XPage_Resize (Width As Int, Height As Int)
    Log("EVENT - BusinessCard::B4XPage_Resize")
    LoadCard (AppGlobals.CardFullContent)
End Sub


Thank you for your suggestion (above you can see the relevant code).
Now the right item (clicked by the user within the "PageA") is loaded inside the "PageB", but I still have the same issue of the cutted page, i.e. scrolling the page only a part of the fields appear and the page ends without displaying the remaining fields (I always speak on the B4i side of my B4XPages App) .

This (page cut) problem appears to be solved by calling the sub "LoadCard ()" within the B4XPage_Resize event.

So the page is displayed correctly, at 100% of its height (vertical length) only and exclusively if LoadCard () is called inside B4XPage_Resize.

And that's the point: B4XPage_Resize is only called the first time the second "PageB" page is called with .ShowPage ().

I can't figure out how to solve the problem but I have to solve it because soon I will have to publish the app on the App Store for my client :-(
 
Last edited:
Upvote 0

luke2012

Well-Known Member
Licensed User
Longtime User
I can't help you there either, make an example project which shows the error.

Hi Alexander, first of all thanks for your appreciated help.
Here is a post where I you can see layout files and other details:


Note: as suggested by @Andrew (Digitwell) I set the wvCardDesc V. Anchor to top only (see post above #5).

So the 100% (vertical with scrolling) of the page is displayed correctly ONLY when the LoadCard() sub running within B4XPage_Resize event (#iPhoneOrientations: Portrait)

The B4XPage_Resize event is triggered only the first time the B4XPage page is opened (.ShowPage)....

B4X:
Sub B4XPage_Resize (Width As Int, Height As Int)
    Log("EVENT - BusinessCard::B4XPage_Resize")
    LoadCard (AppGlobals.CardFullContent)
End Sub

If the user returns to the previous page and touches another item in the list and the page is called again with ".ShowPage()", the _Resize event is no longer triggered but the "B4XPage_Appear" event is triggered:

B4X:
Private Sub B4XPage_Appear
    Log("EVENT - BusinessCard::B4XPage_Appear")
    
    LoadCard (AppGlobals.CardFullContent)
End Sub

The _Appear event executes exactly the same sub (LoadCard) as the -Resize event but the problem is that the page view is found: the views starting from "lblAddressHeader" on are not displayed.

Here this is the problem I am banging my head on and I can't figure out how to fix it.
 
Upvote 0

luke2012

Well-Known Member
Licensed User
Longtime User
UPDATE: I think I solved it by carefully reading Erel's tutorial (B4XPages).


B4X:
Private Sub CreateItem (cfv As CardFullValue) As B4XView
  
    Private pnl As B4XView = xui.CreatePanel("")
    'pnl.SetLayoutAnimated (0,0,0,100%x, 100%y)
    pnl.SetLayoutAnimated (0,0,0,Root.Width, Root.Height)
  
    '......

End

So instead 100%x, 100%y I'm using Root.Width, Root.Height within CreateItem () that is called by LoadCard().
 
Upvote 0
Top