Android Question Using a list in different activities

Hi folks.
I have started a new project (B4x) in which I am using a list in a combobox.
This list is created with dim items as list
and initialized with: items.initialize at the Main Page and then put into the combobox.
Now, I would like to be able to make changes to this list eg. deleting some items in another activity (page).
How can I use the current list from the main page in my other page, edit it and use the changed list again in the main page?
Do I have to save the list first, then load the list into my other activity and save the edited list and finally reload it in the main activity?
That would seem really inconvenient, but it probably would work...

Thanks for your help.
 

mangojack

Expert
Licensed User
Longtime User
Firstly , Is this a B4XPages project (if not , it should be ) , as you refer to Activities and Pages ...

In a B4X Pages Project ..

In B4XMainPage .... Class Globals
B4X:
Public  MyList As List

Then in the MainPage , B4XPage_Created or B4XPage_Appear sub , Initialise and populate your list.


In all Other Pages you wish to reference that list.
B4X:
Sub Class_Globals
    Private MainPage As B4XMainPage
B4X:
Sub B4XPage_Created
    MainPage = B4XPages.MainPage

You should now be able to interact with that main list from anywhere in the other pages with...
B4X:
Log("List Entry 3" & MainPage.MyList.Get(2))
 
Last edited:
Upvote 1

emexes

Expert
Licensed User
How can I use the current list from the main page in my other page, edit it and use the changed list again in the main page?

Making the list accessible across different activities would seem like a good start, eg in the Starter module (program code tab):

Starter module:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim Items As List                                                                           
End Sub

Sub Service_Create
    'This is the program entry point.
    'This is a good place to load resources that are not specific to a single activity.
    Items.Initialize
    Items.Add("First")
    Items.Add("Second")
    Items.Add("Third")
End Sub
 

Attachments

  • 1724200695646.png
    1724200695646.png
    9.2 KB · Views: 34
Upvote 0
Thanks ManGoJack, Emexes for the help provided...
Well, I would like to point out that I am developing with B4x - not B4a.
I was refering to activities and pages interchangeably not knowing there was a real difference between those two terms , probably because I started out with B4A using activities.
Anyways, I will be more careful next time I post something here paying attention to the fact that there is a difference.
Nonetheless, I really appreciate the advice and I am going to give it a shot implementing it as suggested.
 
Upvote 0
Top