Android Question Search and highlight

yiankos1

Well-Known Member
Licensed User
Longtime User
Good morning my friends,
I use an ultimate list view and toolbar search view. Is there any way to highlight text in listview when this sub is called:

B4X:
Sub Search_QueryChanged (Query As String)

Thank you in advance,
At your service
 

Dave O

Well-Known Member
Licensed User
Longtime User
Not sure if this is what you're looking for, but in my Quick Proto app, there's a search screen that highlights text in an UltimateListView, like this:

B4X:
Sub resultsULV_ContentFiller(ItemID As Long, LayoutName As String, LayoutPanel As Panel, Position As Int)
    ...
    Dim nameLabel As Label = LayoutPanel.GetView(1)
    nameLabel.Text = highlightTextInString(c.buildPageNameInCurrent(tempPage), searchField.Text)  
    Dim noteLabel As Label = LayoutPanel.GetView(2)
    noteLabel.Text = highlightTextInString(getSurroundingText(tempPage.pageNote, searchField.Text, noteLabel), searchField.Text)
End Sub

Sub highlightTextInString(bodyText As String, searchText As String) As RichString
    Dim rs As RichString
    rs.Initialize(bodyText)
    Dim startIndex As Int = bodyText.ToLowerCase.IndexOf(searchText.ToLowerCase)
    If startIndex > -1 Then                    'match found
        Dim endIndex As Int = startIndex + searchText.Length
        rs.BackColor(c.COLOR_HIGHLIGHT, startIndex, endIndex)
    End If
    Return rs
End Sub
 
Upvote 0

yiankos1

Well-Known Member
Licensed User
Longtime User
Thank you very much my friend. That was exactly what i wanted.
 
Upvote 0

Similar Threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…