Private Sub SetTextToCell (Text As String, lbl As B4XView, Searchable As Boolean)
If Searchable = False Or HighlightSearchResults = False Or Text = Null Then
lbl.Text = Text
Else
#if B4J
Dim parent As B4XView = lbl.Parent
If parent.GetView(parent.NumberOfViews - 1).Tag = TextPaneTag Then
parent.GetView(parent.NumberOfViews - 1).RemoveViewFromParent
End If
#End If
If FilterText = "" Then
lbl.Text = Text
Else
Dim x As Int = Text.ToLowerCase.IndexOf(FilterText)
If x = -1 Or (PrefixSearch And x > 0) Then
lbl.Text = Text
Return
End If
#if B4A or B4i
Dim cs As CSBuilder
cs.Initialize.Append(Text.SubString2(0, x)).Color(HighlightTextColor).Append(Text.SubString2(x, x + FilterText.Length)).Pop
cs.Append(Text.SubString(x + FilterText.Length))
#if B4A
lbl.Text = cs
#else if B4i
Dim l As Label = lbl
l.AttributedText = cs
#End If
End If
#Else
TextFlow.Reset
If x > 0 Then
TextFlow.Append(Text.SubString2(0, x)).SetColor(TextColor).SetFont(LabelsFont)
End If
TextFlow.Append(Text.SubString2(x, x + FilterText.Length)).SetColor(HighlightTextColor).SetFont(LabelsFont)
If x + FilterText.Length < Text.Length Then
TextFlow.Append(Text.SubString(x + FilterText.Length)).SetColor(TextColor).SetFont(LabelsFont)
End If
Dim TextPane As B4XView = TextFlow.CreateTextFlow
TextPane.Tag = TextPaneTag
lbl.Text = ""
parent.AddView(TextPane, 0, parent.Height / 2 - 12, parent.Width, parent.Height / 2)
End If
#end if
End If
End Sub