I'm sure there is a logical explanation for this strange behaviour but I have been looking at this for some time now and can't work out what is going wrong. I'm trying to add some views (labels) to the inner panel (pnlOptions) of a scrollview and have the following lines of code:
B4X:
For i = 0 To Cursor1.RowCount - 1
Cursor1.Position = i
optcode = Cursor1.GetString("code")
option = Cursor1.GetString("item")
optprice = Cursor1.GetString("price")
Dim lbltick As Label
lbltick.Initialize(OptionCheck)
lbltick.color = Main.white
lbltick.TextColor = Colors.Black
lbltick.TextSize = FontSize + 2
lbltick.tag = "#" & (4 + i)
If i = 0 Then lbltick.Text = tickchar
pnlOptions.AddView(lbltick,0,lbltop,lblwidth,RowHeight)
where sub OptionCheck does some stuff when the label is tapped. When I debug through this code I find that when the 'lbltick.Initialize(OptionCheck)' code is executed it jumps immediately to sub OptionCheck. And when I run the project tapping on lbltick doesn't execute OptionCheck. I have similar code in other parts of the project and this does not happen. I'm just can't figure this out although I'm sure it's something really simple that I am missing.
Thanks guys, now I just feel silly for missing that. What put me off was in my previous use of this I had a line
B4X:
label1.initialize(rowcheck)
So without checking the correct syntax I used the same format. However, in the above code I had declared rowcheck as a string which was the name of the sub to use. Funny how you can get mesmerized by looking at a piece of code and missing the obvious.