Android Question List of list has (String) in front

Nickelgrass

Active Member
Licensed User
Longtime User
Hello,
i am creating a list of lists. The inner list holds a string and two ints. Now if I try to innerlist.get(x) it does not work. Only innerlist(x). And then the string has (String) in front of it.

List of list:
Sub Process_Globals
    dim const outerlist as list = Array( _
        Array as list("some string", 1, 2), _
        Array as list("some other string", 3, 4), _
        Array as list("some new string", 5, 6))
End Sub

Sub somesub()
    For i = 0 to outerlist.size - 1
        dim item() as list = outerlist.get(i)
        log(item(0).as(String))
    Next
EWnd Sub

How can I do this differently? I would like to assign the values directly an not load them individually.
Edit: seems it only works in debug mode so I will have to do it differently
 

William Lancee

Well-Known Member
Licensed User
Longtime User
B4X:
'SHOULD BE

Dim Items As List = outerlist.Get(i)
Log(items.Get(0))

First part is wrong too.
You are confusing Lists with Arrays.
If you make the inner list an array of objects you're good to go.

B4X:
    Dim outerlist As List = Array(Array("some string", 1, 2), Array("some other string", 3, 4), Array("some new string", 5, 6))

    For i = 0 To outerlist.size - 1
        Dim items() As Object = outerlist.get(i)
        Log(items(0))
    Next

Note: It also doesn't make sense to make a List into a Constant, it can still be modified, try it.
 
Last edited:
Upvote 2

Nickelgrass

Active Member
Licensed User
Longtime User
B4X:
'SHOULD BE

Dim Items As List = outerlist.Get(i)
Log(items.Get(0))

First part is wrong too.
You are confusing Lists with Arrays.
If you make the inner list an array of objects you're good to go.

B4X:
    Dim outerlist As List = Array(Array("some string", 1, 2), Array("some other string", 3, 4), Array("some new string", 5, 6))

    For i = 0 To outerlist.size - 1
        Dim items() As Object = outerlist.get(i)
        Log(items(0))
    Next

Note: It also doesn't make sense to make a List into a Constant, it can still be modified, try it.
Worked, thanks. Also for pointing out the thing with array and list.
 
Upvote 0
Top