B4J Question Keeping B4XTable On B4XMainPage Updated From Subs On Other Pages

cklester

Well-Known Member
Licensed User
I've got a table on my B4XMainPage that shows a list of active items. I have an Items Manager page where items can be activated/deactivated. These active items are kept in a KeyValueStore to which all pages have access through a code module.

I'd like to keep the table on B4XMainPage updated for every time an item is activated/deactivated on the Items Manager page. What's the best way to do that?

Should I call back to a function on B4XMainPage for each activation/deactivation? Is there a way to broadcast an "Active Items Were Updated" message/event, so that any or all pages can subscribe to it? (Who knows? I might have other pages that need the updated active items listed.)
 

cklester

Well-Known Member
Licensed User
I'm using

B4X:
CallSubDelayed(B4XPages.MainPage,"PopActiveExchangesTable")

which works great! but seems smelly. What if I want to use this Module in another app that does not have a "PopActiveExchangesTable" sub in B4XMainPage?

Seems like broadcasting a message would be better.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You should raise an event instead.

B4X:
Sub Class_Globals
   Private mEventName As String 'ignore
   Private mCallBack As Object 'ignore
  Private xui as XUI
End Sub

Public Sub Initialize (Callback As Object, EventName As String)
   mEventName = EventName
   mCallBack = Callback
End Sub

'when you want to raise the event:
CallSubDelayed(mCallback, mEventName & "_PopActiveExchangesTable")
 
Upvote 0
Top