2
I have a list of objects and I’m doing a title search.
I use the Normalize to make the comparison by 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 take from mine Edittext. It works, but there is one delay in this comparison, and the search is slightly stalled, giving a delay by typing each letter.
Is there any way to make this comparison faster?
I tested it. It got slightly faster, but the dalay is still present. I solved the problem otherwise, I’ll submit the answer, maybe you can make improvements comments.
– Nichollas Fonseca