I am having a few issues with a project. I need to resolve these issues one at a time. The code below consists of two subs. When the code in the second sub has finished executing, there is an unintended return to the first sub. The two subs behave as if they were intentionally looped, and will persist in executing over and over. :BangHead:
How can I stop a return to sub one, once sub two has finished executing? Help in this regard would be greatly appreciated.
How can I stop a return to sub one, once sub two has finished executing? Help in this regard would be greatly appreciated.
B4X:
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