B4J Question Initializing many lists together, any convenient solutions?

MegatenFreak

Active Member
Licensed User
Hi. I'm trying to clean up my code. One of the annoying things is that It is full of places where I initialize a large number (for example, 30) lists at once. Something like:
B4X:
Dim a, b, c, d as List
a.Initialize
b.Initialize
c.Initialize
d.Initialize
I was wondering if there is a "cleaner" way to do this. I tried the following:
B4X:
For Each x As List in Array(a, b, c, d)
    x.Initialize
Next
It didn't work. The code runs, but I get an exception saying the lists are not initialized.
Any ideas?
 

MegatenFreak

Active Member
Licensed User
This will work:
B4X:
For Each x As List in Array As List(a, b, c, d)

However if you have multiple similar lists then you should probably switch to a single list with custom types.
Thanks. It worked perfectly.
Actually, the lists hold information loaded from a database table. Each list holds the value of a specific column in all the records. I suppose it would have been a lot better if I had used custom types.
 
Upvote 0
Top