Android-SimpleAdapter过滤器查询,如何忽略重音符号? [英] Android - SimpleAdapter filter query, how to ignore accents?

查看:67
本文介绍了Android-SimpleAdapter过滤器查询,如何忽略重音符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在使用ContentProvider作为联系人,以从设备中检索联系人,并允许用户通过键入EditText来过滤结果.

I am currently using the ContentProvider for contacts to retrieve the contacts from the device and allowing the user to filter the results by typing into an EditText.

为此,我在SimpleAdapter上设置了过滤器查询,如下所示:

To do so I have set up a filter query on a SimpleAdapter as follows:

    contactsAdapter.setFilterQueryProvider(new FilterQueryProvider() {
        String[] PROJECTION = new String[] {
                ContactsContract.Contacts._ID,
                ContactsContract.Contacts.DISPLAY_NAME,
                ContactsContract.Contacts.HAS_PHONE_NUMBER,
        };
        String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED COLLATE NOCASE ASC";

          public Cursor runQuery(CharSequence constraint) {
            String SELECTION = "LOWER(" + ContactsContract.Contacts.DISPLAY_NAME + ")" 
            + " LIKE '" + constraint + "%' " + "and " + ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '1'";
            Cursor cur = managedQuery(ContactsContract.Contacts.CONTENT_URI, 
                    PROJECTION, SELECTION, null, sortOrder);
            return cur; 
          }
        });
    setListAdapter(contactsAdapter); 

这在大多数情况下都有效,但是当我有重音符号时(例如:TéstCóntact),那么即使用户键入测试联系人",我也希望显示该联系人,但目前没有.

This works in most cases however when I have a contact with an accent (Example: Tést Cóntact) then I want the contact to show up even if the user types in Test Contact, currently it doesn't.

在这种情况下,也不会忽略大小写,但是对于标准字符,例如,如果我有一个名为Omar的联系人并搜索omar匹配,但如果我有一个名为Ómar并搜索ómar则不匹配t匹配.

Also the case is not ignored in this case either whereas for standard characters it is, for example if I have a contact called Omar and search for omar it matches but if I have a contact called Ómar and search for ómar it doesn't match.

有人知道我应该怎么做才能实现我要实现的行为吗?

Does anyone know what I should be doing to implement the behavior I want to achieve?

推荐答案

我会在这里看到2个选项:

I would see 2 options here :

  • 创建一个包含联系人姓名的无口音版本和对实际联系人ID的引用的表
  • 用?代替重音符号?在您的搜索中(这可能不会真正导致用户期望的行为,但是要简单得多)

这篇关于Android-SimpleAdapter过滤器查询,如何忽略重音符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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