Android Code Snippet [B4X] Do something after the user finished typing

This code pattern allows you to do something after the user stopped typing. It can be useful for example if you want to filter a large list or send a http request.

1. Add a process global int variable named TextChangedIndex.
Sub txtFilter_TextChanged (Old As String, New As String)
   TextChangedIndex= TextChangedIndex + 1
   Dim myIndex As Int = TextChangedIndex
   Sleep(1000) 'change duration as needed
   If myIndex <> TextChangedIndex Then Return
   Log("Do whatever you like here...")
End Sub
TextChangeIndex changes whenever the user types. myIndex will only be equal to TextChangeIndex in the last changed event.