如何避免不同的字母的情况下(A,E,I,O,U)搜索模式 - Android电子 [英] How to avoid different letters cases (á, é, í, ó, ú) in search mode - Android

查看:127
本文介绍了如何避免不同的字母的情况下(A,E,I,O,U)搜索模式 - Android电子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个应用程序,应更换默认的联系人电话本,我想添加一个搜索栏,搜索联系人的姓名。

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.

现在我有我自己的数据库中的所有联系人和保持跟踪在任何的EditText变化TextWatcher - 然后建立与用户输入的字符序列的查询。
这是工作得很好,我越来越像所有接触用户搜索以A开头的所有联系人。
现在,我想添加一个新功能,忽略特殊字母,如:A,E,I,O,U

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: á, é, í, ó, ú.

我想,用户可以输入一个,仍然可以得到以A开头的所有联系人
同为e和所有其他字母。

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.

有没有办法在查询本身要做到这一点,或有是Java / Android的给我们完成的东西。

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

感谢。

推荐答案

您可以使用 java.text.Normalizer 剥离口音。

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

f您想在查询中使用它,你应该添加一个字段到包含搜索的文本的简装版本的数据库。

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.

这篇关于如何避免不同的字母的情况下(A,E,I,O,U)搜索模式 - Android电子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆