Android Question B4XDialog and code organization

mmanso

Active Member
Licensed User
Longtime User
Hi all,

Let's say I've 3 or 4 dialogs and each one has it's own layout file.

From what I've been learning about B4X, we build the layouts, we generate the members (variables and methods) and we associate the code to them (great).

My question is:

What's the best practice in organizing the code for this? On the apps I've been developing I end up having a lot of:

screenshot_2021-03-03 07_32_09.png


If we've a layout that has multiple buttons and uses 3 or 4 different dialogs, this list start betting big... also, if the dialogs have similar buttons, let's say "Save" button, we end up having:

btnSave_Click

and we need to start thinking on having a dialog name prefix to identify the method, like:

btnDlg1Save_Click

Is there any "best practice" to deal with this? Is there any recomended way to organize the code for these situations or this is the way it is and I'm on the right path here?

Thanks for the help.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can implement the complete dialog in a class of its own.

You can then show the dialog with:
B4X:
Dim SaveDialog As MySaveDialog
SaveDialog.Initialize(Root) 'or activity. You can reuse it instead of initializing again each time
Wait For (SaveDialog.Show) Complete (Result As Int)

'Inside the class
Public Show As ResumableSub
Wait For (Dialog.Show(...)) Complete (Result As Int)
Return Result
End Sub
 
Upvote 0

mmanso

Active Member
Licensed User
Longtime User
Hi Erel,

The MySaveDialog needs to inherit from any base dialog class? If possible, could you paste a simple example of a possible MySaveDialog class?

All the samples I found in the forum are dialogs created on the fly when needed (not in custom classes).

Thanks in advance.
 
Upvote 0
Top