Hello guys,
I've seen this issue in many other threads here, but now that I need it I'm unable to find the answer.
I cast labels on the activity and want to save their information for later retrieval (.text, .left, .top, etc).
I created a map with the fields I want to save.
I lstLetters.add information held in my mapLetters map, but after the main loop is complete, only the last occurence data is present in lstLetters.
What am I doing wrong? What is the correct why to save and retrieve from my lstLetters list?
I've seen this issue in many other threads here, but now that I need it I'm unable to find the answer.
I cast labels on the activity and want to save their information for later retrieval (.text, .left, .top, etc).
I created a map with the fields I want to save.
I lstLetters.add information held in my mapLetters map, but after the main loop is complete, only the last occurence data is present in lstLetters.
What am I doing wrong? What is the correct why to save and retrieve from my lstLetters list?
B4X:
Type LetterCoord(index As Int, letter As String, left As Int, top As Int, found As Boolean)
Sub Activity_Create(FirstTime As Boolean)
Private mapLetters As LetterCoord
Private lstLetters As List
' When running this loop, only information regarding last interation is listed
For i = 0 To lstLetters.Size - 1
Log("lstLetters " & i & ") " & lstLetters.Get(i))
Next
End Sub
Sub DrawWord(word As String, left As Int, top As Int, empty As Boolean)
For i = 0 To word.Length - 1
lblLetter(i).Initialize("lblLetter")
lblLetter(i).Text = word.SubString2(i, i+1)
lblLetter(i).TextColor = Colors.White
lblLetter(i).TextSize = 50
lblLetter(i).Background=cd
lblLetter(i).Gravity = Gravity.CENTER_HORIZONTAL
lblLetter(i).left = left
Activity.AddView(lblLetter(i), lblLetter(i).left, top, 45dip, 80dip)
left = left + 55dip
If empty <> True Then
' Want to save lblLetter(i) information on a list for later retrieval
mapLetters.Initialize
mapLetters.index = i
mapLetters.letter = lblLetter(i).Text
mapLetters.left = lblLetter(i).Left
mapLetters.top = top
mapLetters.found = False
' Not sure if I'm doing right because only the last interaction data is kept, others are overwritten
lstLetters.Add(mapLetters)
Log(i & ") " & mapLetters)
End If
Next
End Sub