I have a list of objects and I'm doing a title search.
I use Normalizer to make the comparison ignoring accents:
public static boolean containsIgnoreCaseAndAccents(String haystack, String needle) {
final String hsToCompare = removeAccents(haystack).toLowerCase();
final String nToCompare = removeAccents(needle).toLowerCase();
return hsToCompare.contains(nToCompare);
}
public static String removeAccents(String string) {
return ACCENTS_PATTERN.matcher(Normalizer.normalize(string, Normalizer.Form.NFD)).replaceAll("");
}
And the search:
for(Object o : allObjects){
if(o.getTitle()!=null && containsIgnoreCaseAndAccents(o.getTitle(), text)) {
searchObjects.add(o);
}
}
The text I get from my EditText . It works, however there is a delay in this comparison, and the search gets slightly caught, giving a delay as you type each letter.
Is there any way to do this comparison faster?