Android Question How to List.Get correct object at index.

jparkerri

Member
Licensed User
Longtime User
I'm trying to build a List of objects, and then List.Get(i) one at a time. However, when I List.Get(i), it always returns the last entry in the List. What am I doing wrong?

Here's a simplified example:

Sub Process_Globals
Type QUOTES(Symbol As String)
End Sub

Sub Globals
Dim Q As QUOTES
Dim quoteList As List
End Sub

Sub Activity_Create(FirstTime As Boolean)
quoteList.Initialize
Q.Initialize
End Sub

Sub Activity_Resume
Dim quo As QUOTES

Q.Symbol = "A"
quoteList.Add(Q)
Log ("ListSize = " & quoteList.Size & " " & Q)
Q.Symbol = "B"
quoteList.Add(Q)
Log ("ListSize = " & quoteList.Size & " " & Q)
Q.Symbol = "C"
quoteList.Add(Q)
Log ("ListSize = " & quoteList.Size & " " & Q)

For k = 0 To quoteList.Size - 1
quo.Initialize
quo = quoteList.Get(k)
Log ("K = " & k & " " & quo)
Next
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
 

JTmartins

Active Member
Licensed User
Longtime User
yeap...As mc73 said

if you do not "clean" quo inside the loop you will endup with only the last value. Dim quo will "clean" the variable.

quo.initialize does not do that job.
 
Upvote 0
Top