Android Question Unable to use list of types

Serge Bertet

Active Member
Licensed User
Hello all, here is a basic question I can't solve. Surely something simple.
Here is my code :
B4X:
Sub Globals
    Type arrAnim(index As Int, time As Int, value As Int)
    Dim myArr As arrAnim
End Sub


Sub TestList
Dim myList As List
Dim time As Long

    time = DateTime.Now
    myList.Initialize
    For i = 0 To 10
        myArr.time = DateTime.Now - time
        myArr.value = i * 3
        myArr.index = i
        myList.Add(myArr)
    Next
End Sub

At the end I get a list that contains all items with same values.
Too obvious to find it by myself

Serge
 

Serge Bertet

Active Member
Licensed User
You have to create a new myArr object each time you add it to your list, so you must declate it (myArr) inside the loop.

For i = 0 to 10
Dim myArr as arrAnim

(remove the declaration from the sub Globals)

I was thinking a way like that ... but Dim inside a loop is strange for me (I come from Pascal language).
I'll give it a try ... thank you very much for you help.

Another thing about lists : may I trust the arrangement or do I need to use an index to sort elements?

Serge
 
Upvote 0

Serge Bertet

Active Member
Licensed User
Great video tutorial, thx, I'll keep the link.

Serge
 
Upvote 0
Top