I remember better If I understand how things work. Learning rote will be gone from my head in a day so it would really help if someone can tell me what is going on here.
Thanks in advance.
So, Wrote this in B4J, works fine but failed in B4A:
Dim MaxWidth As Float, HardCharWidth As Float, TxtPlus As String, Fnt As B4XFont = xui.CreateDefaultFont(15)
Dim BXV As B4XView = xui.CreatePanel("")
Dim cvs1 As B4XCanvas
cvs1.Initialize(BXV)
MaxWidth = cvs1.MeasureText($"MMMMMMMMMM |"$, Fnt).Width
It was failing on the initialize line. Finally figured out that in B4A it must be added to something.
So this worked, added the view to an existing View, then removed it (lines 4 and 7):
Dim MaxWidth As Float, HardCharWidth As Float, TxtPlus As String, Fnt As B4XFont = xui.CreateDefaultFont(15)
Dim BXV As B4XView = xui.CreatePanel("")
Dim cvs1 As B4XCanvas
WCCodeCmbo.mBase.AddView(BXV, 0, 0, 500dip, 100dip)
cvs1.Initialize(BXV)
MaxWidth = cvs1.MeasureText($"MMMMMMMMMM |"$, Fnt).Width
BXV.RemoveViewFromParent
The part that threw me, though was I had additional lines that measured the text AFTER I removed the panel.
So this worked as well! (line 8)
Dim MaxWidth As Float, HardCharWidth As Float, TxtPlus As String, Fnt As B4XFont = xui.CreateDefaultFont(15)
Dim BXV As B4XView = xui.CreatePanel("")
Dim cvs1 As B4XCanvas
WCCodeCmbo.mBase.AddView(BXV, 0, 0, 500dip, 100dip)
cvs1.Initialize(BXV)
MaxWidth = cvs1.MeasureText($"MMMMMMMMMM |"$, Fnt).Width
BXV.RemoveViewFromParent
MaxWidth = cvs1.MeasureText($"MMMMMMMMMM |"$, Fnt).Width
So, why does it need to be added to a view in B4A (and presumably B4i) but not in B4J?
And why does it still work after removing it?