Sub pop_Download2Completed (Success As Boolean, MessageId As Int, Message As String, MainHeaders As Map)
Dim arraySubject(messageCount) As String
Dim arrayFrom(messageCount) As String
delFlag = True
SelectFlag = False
aIndex = 0
MessageId = 2
Do While aIndex < messageCount
arraySubject(aIndex) = (MainHeaders.Get("SUBJECT"))
arrayFrom(aIndex) = (MainHeaders.Get("FROM"))
If aIndex < messageCount - 1 Then ' don't execute next line if header downloads completed
pop.DownloadMessage2(MessageId, 0, True, False)
End If
aIndex = aIndex + 1
MessageId = MessageId + 1
Loop
pop.Close ' the connection will be closed
'ToastMessageShow("Download2Completed", False) ' For testing only
CreateScrollView
End Sub
Sub CreateScrollView
'#####################################################################################
'# ScrollView does not populate correctly. If say two items in array, the first item #
'# is displayed in both checkboxes - then second item is displayed in both checkboxes#
'# overwriting the previous first items displayed. Strange behaviour I can't resolve.#
'# This loop seems to be persist in a random manner irrespective of messageCount ??? # #
'#####################################################################################
Dim ScrollView1 As ScrollView
Dim lstChecks As List
Dim height As Int : height = 40dip
Dim Panel1 As Panel
ScrollView1.Initialize(0)
Panel1 = ScrollView1.Panel
Activity.AddView(ScrollView1, 5, 25, 99%x, 81%y)
lstChecks.Initialize
aIndex = 0
For i = 1 To messageCount
'ToastMessageShow(aIndex & " Why does loop persist beyond once?", False) ' For testing only
Dim chk As CheckBox
chk.Initialize("chkBoxSelection")
Subject = arraySubject(aIndex) 'get the item from the array
chk.Text = Subject
chk.TextSize = FontSize
chk.TextColor = FontColor
chk.tag = i
lstChecks.Add(chk)
Dim lbl1 As Label
lbl1.Initialize("")
From = arrayFrom(aIndex) 'get the item from the array
lbl1.Text = From
lbl1.Gravity = Gravity.CENTER_VERTICAL
lbl1.TextSize = FontSize
lbl1.TextColor = FontColor
Panel1.AddView(chk, 0, height * (i - 1), 49%x, height)
Panel1.AddView(lbl1, 50%x, height * (i - 1), 49%x, height)
aIndex = aIndex + 1
Next
Panel1.height = lstChecks.Size * height
End Sub