Android Question [B4X] Cross Platform Project Questions ...

mangojack

Expert
Licensed User
Longtime User
Hi all ... I am currently combining B4A / B4J project and hit a small bump.

Both projects have Activity / Modules ... Main, Income, Expenses, Calendar & Summary. (95% code transferred to shared classes)

The Main activity/module displays 4 panels / labels acting as buttons to move between the Activity / Modules.

I have been able to reduce code in B4A ...

previously ..
B4X:
Sub pnlButton_Click   
    Dim pnl As Panel = Sender 
  
    Select pnl.Tag
        Case "Income"
            StartActivity(Income)
        Case "Expenses"
            StartActivity(Expenses)
'.............................

revamped ..
B4X:
Dim pnl As B4XView = Sender 
StartActivity(pnl.Tag)



But .. is there anyway to do something similar with B4J ?

B4X:
Sub pnlButton_MouseClicked (EventData As MouseEvent)   
    Dim pnl As B4XView = Sender 
  
    Select pnl.Tag   
        Case "Income"
            Income.StartModule        'StartModule is a Public Sub to initialize form / class etc ...  (if uninitialized)
        Case "Expenses"
            Expenses.StartModule



And if I may .. a second question .

Is it safe / acceptable to use compilation tags with Event Sub signatures ie:
B4X:
#if B4A
    Sub pnlButton_Click   
#Else
    Sub pnlButton_MouseClicked (EventData As MouseEvent)
#End If

    'code ..........
End Sub

Many Thanks
 

klaus

Expert
Licensed User
Longtime User
Last edited:
Upvote 0

mangojack

Expert
Licensed User
Longtime User
@klaus .. thanks for that . I have used your cross platform examples as a reference/starting point for this undertaking.

Declare the Buttons as B4XViews, the you have the Click event in all three platforms, withexactly the same code.

That is good enough reason to replace the Panel/Panes with buttons.


I am still hoping for an answer to my main question though ...

in B4A I can start an Activity using a Tag ..
B4X:
Dim pnl As B4XView = Sender
StartActivity(pnl.Tag)


But .. is there anyway to do something similar with B4J to start/load another code module/ Form

present code ...
B4X:
Sub pnlButton_MouseClicked (EventData As MouseEvent)
  Dim pnl As B4XView = Sender

  Select pnl.Tag
    Case "Income"
      Income.StartModule 'StartModule is a Public Sub to initialize form / class etc ... (if uninitialized)
    Case "Expenses"
      Expenses.StartModule
     '...............................................

Thanks and Regards
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Have you looked at the B4X_TwoScreens and B4X_SQLiteLight2 projects?
They handle several 'screens' (activities, forms, pages) with the minimal cross specific code and maximum same code.
You can download the source code for all booklets from HERE.
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Have you looked at the B4X_TwoScreens and B4X_SQLiteLight2 projects?

@klaus .. Yes I have read and studies those projects. I have all the Source Code.

Maybe I'm not explaining my question well. I will have another look / rethink and go from there.

Thanks for all the input by all

Regards
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
How do I call Multiple Modules Public Sub (from the Main Module) ... using a .Tag property ?
Yes. The principle remains the same as with standard views.
But the calling routines are platform specific, different in B4A, same for B4i and B4J, example below.

B4X:
Private Sub btnSetFilter_Click
#If B4A
    StartActivity(Filter)
#Else
    Filter.Show
#End If
End Sub
In the example above, Fliter is a platform specific module. An Activity for B4A and code modules for B4i and B4J.
 
Last edited:
Upvote 0

mangojack

Expert
Licensed User
Longtime User
I have solved my main issue / question by setting the pnl.Tag's property at startup with the various Module names/objects ..
then using CallSub(pnl.Tag, "StartModule") on later panel / pane (soon to be button) clicks.

I knew there would be a simple solution but just could not think it to start.

At least I was able to throw away the Select Case block.

Thanks again.

Cheers.
 
Upvote 0
Top