Private WordList As List
Private FoundList As Map
Private searchWord As String
Type CardData (Content As String, highlightIndex As Int, wordPosition As Int)
Private Sub edtWord_TextChanged (Old As String, New As String)
Sleep(0)
If edtWord.Text = "" Then
CLV1.Clear
Return
End If
Dim startTime As Long = DateTime.Now
searchWord = New.ToLowerCase.trim
FoundList.Clear
CLV1.Clear
For i = 0 To WordList.Size - 1
Dim word As String = WordList.Get(i) ' <-- this is the word with its order in the wordlist
Dim mArray() As String = Regex.Split(" ", word)
Dim idx1 As Int = 0 ' <-- to store the index of highlighted string
For j = 0 To mArray.Length-1
Dim idx2 As Int = 0
idx2 = mArray(j).ToLowerCase.CompareTo(searchWord)
If idx2 = 0 Then '<-- we found the string in mArray that matches with searchWord
For k = 0 To j-1
idx1 = idx1 + mArray(k).Length ' <-- to find the length of words before this matched string
Next
idx1 = idx1 + j '<--- for adding of space number before each word
FoundList.Put(word, idx1) ' Add the word together with the index of the highlighted string (for CSBuilder later to populate the cardlist if necessary)
' ADD THE ITEM TO THE CUSTOM LISTVIEW
Dim cd As CardData
cd.Initialize
cd.Content = word
cd.highlightIndex = idx1
cd.wordPosition = i
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(0, 0, 0, CLV1.AsView.Width, 60dip)
CLV1.Add(p, cd)
' EXIT THE LOOP
Exit
Else
Continue
End If
idx1 = 0
Next
Next
LogColor("Searching time = " & (DateTime.Now - startTime) & " Foundlist.Size = " & FoundList.Size & " items", Colors.Blue)
End Sub