I have a TextView in a ScrollView that is loaded with a text file and then passed to a CSBuilder sub. The ScrollView presents fine but the FIRST time I load the page the text is very small (much smaller than what is set in Designer). The color formatting presents properly but the bold formatting doesn't take and font size formatting is as described above. All subsequent loads of the page format properly. I've used tvScroll as both TextView and B4XView with the same results. Any suggestions?
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Private pg As Page
Private btnClear As B4XView
Private btnInfo As B4XView
Private btnSubmit As B4XView
Private pnlInfo As Panel
Private ScrollView1 As ScrollView
Private tvScroll As B4XView
Private RawScrollText As String
End Sub
Public Sub ShowRules
If pg.IsInitialized = False Then
pg.Initialize("pg")
pg.RootPanel.LoadLayout("Rules")
End If
RawScrollText = File.ReadString(File.DirAssets, "rules.txt")
tvScroll.Text = RawScrollText
Main.NavControl.ShowPage(pg)
MultiLine(tvScroll)
tvScroll.Width = ScrollView1.Width
ScrollView1.ContentHeight = tvScroll.Height
ScrollView1.ContentWidth = tvScroll.Width
ScrollView1.Panel.AddView(tvScroll, 0, 0, tvScroll.Width, tvScroll.Height)
End Sub
Private Sub Rules_Resize(Width As Int, Height As Int)
tvScroll.Text = RawScrollText
Log("Rules_Resize")
MultiLine(tvScroll)
End Sub
Sub MultiLine(lbl As TextView) 'Parse a string and customize colors, links, etc.
Dim StrPtr As Int ' Tracking pointer to individual characters in StringA
Dim Chart As String ' Character holder for cs build
Dim ColorChange As Boolean ' Color on/off
Dim BoldChange As Boolean ' Underline on/off
Dim SizeUp As Boolean ' Increase Font Size to 18pt
Dim SizeDown As Boolean ' Decrease Font Size to 4pt
Dim UnderChange As Boolean ' Underline on/off
Dim cs As CSBuilder
cs.Initialize
Chart = lbl.Text.SubString2(StrPtr, StrPtr+1)
cs.Font(Font.CreateNew(16))
Do While Chart <> "<"
Select Chart
Case "&" ' Change Color to Blue
If ColorChange = True Then
ColorChange = False
cs.Pop
Else
cs.Color(Colors.Blue)
ColorChange = True
End If
Case ";" ' Change Color to Burgundy
If ColorChange = True Then
ColorChange = False
cs.Pop
Else
cs.Color(Main.clrBurg)
ColorChange = True
End If
Case "*" ' Change Type to Bold
If BoldChange = True Then
BoldChange = False
cs.Pop
Else
cs.Font(Font.CreateNewBold(16))
BoldChange = True
End If
Case "~" ' Change Type to Underline
If UnderChange = True Then
UnderChange = False
cs.Pop
Else
cs.Underline
UnderChange = True
End If
Case "^" ' Change Font Size Up
If SizeUp = True Then
SizeUp = False
cs.Pop
Else
cs.Font(Font.CreateNew(16))
SizeUp= True
End If
Case "%" ' Change Font Size Down
If SizeDown = True Then
SizeDown = False
cs.Pop
Else
cs.Font(Font.CreateNewBold(16))
SizeDown = True
End If
Case "#"
cs.Color(Colors.Blue)
cs.Underline.Font(Font.CreateNewBold(16))
cs.Link("https://sites.google.com/view/yellowlabel/home")
cs.Append("visit our website.").PopAll
cs.PopAll
Case "$"
cs.PopAll
cs.Font(Font.CreateNew(16))
Case Else
cs.Append(Chart)
End Select
StrPtr = StrPtr + 1
Chart = lbl.Text.SubString2(StrPtr, StrPtr+1)
Loop
cs.PopAll
lbl.AttributedText = cs
End Sub
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Private pg As Page
Private btnClear As B4XView
Private btnInfo As B4XView
Private btnSubmit As B4XView
Private pnlInfo As Panel
Private ScrollView1 As ScrollView
Private tvScroll As B4XView
Private RawScrollText As String
End Sub
Public Sub ShowRules
If pg.IsInitialized = False Then
pg.Initialize("pg")
pg.RootPanel.LoadLayout("Rules")
End If
RawScrollText = File.ReadString(File.DirAssets, "rules.txt")
tvScroll.Text = RawScrollText
Main.NavControl.ShowPage(pg)
MultiLine(tvScroll)
tvScroll.Width = ScrollView1.Width
ScrollView1.ContentHeight = tvScroll.Height
ScrollView1.ContentWidth = tvScroll.Width
ScrollView1.Panel.AddView(tvScroll, 0, 0, tvScroll.Width, tvScroll.Height)
End Sub
Private Sub Rules_Resize(Width As Int, Height As Int)
tvScroll.Text = RawScrollText
Log("Rules_Resize")
MultiLine(tvScroll)
End Sub
Sub MultiLine(lbl As TextView) 'Parse a string and customize colors, links, etc.
Dim StrPtr As Int ' Tracking pointer to individual characters in StringA
Dim Chart As String ' Character holder for cs build
Dim ColorChange As Boolean ' Color on/off
Dim BoldChange As Boolean ' Underline on/off
Dim SizeUp As Boolean ' Increase Font Size to 18pt
Dim SizeDown As Boolean ' Decrease Font Size to 4pt
Dim UnderChange As Boolean ' Underline on/off
Dim cs As CSBuilder
cs.Initialize
Chart = lbl.Text.SubString2(StrPtr, StrPtr+1)
cs.Font(Font.CreateNew(16))
Do While Chart <> "<"
Select Chart
Case "&" ' Change Color to Blue
If ColorChange = True Then
ColorChange = False
cs.Pop
Else
cs.Color(Colors.Blue)
ColorChange = True
End If
Case ";" ' Change Color to Burgundy
If ColorChange = True Then
ColorChange = False
cs.Pop
Else
cs.Color(Main.clrBurg)
ColorChange = True
End If
Case "*" ' Change Type to Bold
If BoldChange = True Then
BoldChange = False
cs.Pop
Else
cs.Font(Font.CreateNewBold(16))
BoldChange = True
End If
Case "~" ' Change Type to Underline
If UnderChange = True Then
UnderChange = False
cs.Pop
Else
cs.Underline
UnderChange = True
End If
Case "^" ' Change Font Size Up
If SizeUp = True Then
SizeUp = False
cs.Pop
Else
cs.Font(Font.CreateNew(16))
SizeUp= True
End If
Case "%" ' Change Font Size Down
If SizeDown = True Then
SizeDown = False
cs.Pop
Else
cs.Font(Font.CreateNewBold(16))
SizeDown = True
End If
Case "#"
cs.Color(Colors.Blue)
cs.Underline.Font(Font.CreateNewBold(16))
cs.Link("https://sites.google.com/view/yellowlabel/home")
cs.Append("visit our website.").PopAll
cs.PopAll
Case "$"
cs.PopAll
cs.Font(Font.CreateNew(16))
Case Else
cs.Append(Chart)
End Select
StrPtr = StrPtr + 1
Chart = lbl.Text.SubString2(StrPtr, StrPtr+1)
Loop
cs.PopAll
lbl.AttributedText = cs
End Sub