Android Question saving and loading lists with respect to data type

tmf

Member
Licensed User
Longtime User
So I have a list

dim list1 as list

then I add 3 booleans

list1.add(false)
list1.add(true)
list1.add(false)

then I save the list

File.WriteList(File.DirDefaultExternal, "mylist", list1)

then later I read the list

list1.clear()
list1 = File.ReadList(File.DirDefaultExternal, "mylist")

My issue is it seems this list is now of type String and not boolean

How do people deal with this??

I searched and found no answers.

Richard.
 

tmf

Member
Licensed User
Longtime User
OK I am getting ultra confused, I read lists and arrays are considered the "same thing" so you can do

dim a as list ' list of maybe "I","AM","TESTING"
dim b() as string ' and after assignment b(0) = "I" b(1) = "AM" b(2) = "TESTING"
b = a

Basic4android automatically converts regular arrays to lists. So when a List parameter is expected you can pass an array instead.
from https://www.b4x.com/android/help/collections.html

and if this *does* work should dim b() be b(3) or will it "autofill"

RichardS
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I'm not sure that I understand the question. Note that lists and arrays are not considered the same thing.

B4A will automatically convert an array to a list when the parameter type is a List. Other conversions will not happen automatically.

Save list:
B4X:
Dim raf As RandomAccessFile
raf.Initialize(..., ..., False)
raf.WriteB4XObject(YourList, 0)
raf.Close

Load list:
B4X:
Dim raf As RandomAccessFile
raf.Initialize(..., ..., False)
Dim list As List = raf.ReadB4XObject(0)
raf.Close
 
Upvote 0
Top