Frage

I'm building an app that should replace the default contacts phone book, and I want to add a search bar for search a contact's name.

For now I have all the contacts in my own DB and a TextWatcher for keep tracking any change in the editText - then builds a query with the char sequence that the user entered. This is works fine, I'm getting all the contacts the user search like all the contacts starts with "a". Now I want to add a new functionality to ignore special letters like: á, é, í, ó, ú.

I want that the user could type a and still get all the contacts that starts with á the same for e and all the other letters.

Is there a way to do this in the query itself or there is something that Java/Android give us that accomplish that.

Thanks.

War es hilfreich?

Lösung

You can use java.text.Normalizer to strip accents.

String strippedAccent = Normalizer.normalize(someText, Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", "");

f you want to use it in a query, you should probably add a field into your DB containing the stripped-down version of the searchable text.

Andere Tipps

This change worked that quite well for nubdial. It's reasonably fast, too.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top