Thread tutor?

Bas Hamstra

Member
Licensed User
Longtime User
As a newbie my first app runs well: searches for a pattern in a wordlist and displays all words that contain the pattern in a Listview. It takes only few seconds to fill the LV with THOUSANDS of matches and that's in the emulator! Pretty impressive!!!

Now my question during that few seconds the UI is dead. Maybe it's a non-issue, but wouldn't it be nicer to start the searchwork in a seperate thread and keep the UI alive ALWAYS?

Not sure of the complications...bad idea? Anyway I did not see a thread tutorial. I donate my humble beginners app for such a tutorial, see below,
the code is only few lines which shows the power of B4A imo :)

Bas

/*** src ***/

Sub Process_Globals

End Sub

Sub Globals
Dim EditText1 As EditText
Dim ListView1 As ListView
Dim Button1 As Button
Dim List1 As List
End Sub

Sub Activity_Create(FirstTime As Boolean)
ListView1.Initialize("ListView1")
Activity.LoadLayout("StringSearcher")

If File.Exists(File.DirAssets,"woorden.lst") Then
List1 = File.ReadList(File.DirAssets,"woorden.lst")
End If

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub Button1_Click
Dim Word As String
Dim Pat As String

ListView1.Clear
Pat = EditText1.Text

DoEvents ' clear the LV now

For n=0 To List1.Size-1
Word = List1.Get(n)
If Word.Contains(Pat) Then
ListView1.AddSingleLine(Word)
End If
Next

End Sub
 
Top