Searching for text using a text file that holds few kilobytes of data results in the app become unresponsive, extremely sluggish and very slow.
Cause
The issue is cause by the EditText.highlightText(). Whenever a user tries to search for a string, this function tries to finds all instances of the string and replace them with SpannableString. More specifically, EditText.setText() function is extremely slow when setting SpannableText: this function is called for every search instance found.
Solution
Instead of highlighting all search instances, the code now just highlights the first result and once the next button is clicked it will highlight the next result and so on.
Additionally EditText.setText() function appears to be faster then BackgroundColorSpan is used instead of SpannableText.
Issue
Searching for text using a text file that holds few kilobytes of data results in the app become unresponsive, extremely sluggish and very slow.
Cause
The issue is cause by the
EditText.highlightText()
. Whenever a user tries to search for a string, this function tries to finds all instances of the string and replace them withSpannableString
. More specifically,EditText.setText()
function is extremely slow when settingSpannableText
: this function is called for every search instance found.Solution
Instead of highlighting all search instances, the code now just highlights the first result and once the next button is clicked it will highlight the next result and so on.
Additionally
EditText.setText()
function appears to be faster thenBackgroundColorSpan
is used instead ofSpannableText
.