过滤联系人姓名并删除电子邮件地址

发布于 2025-01-07 02:54:08 字数 2297 浏览 0 评论 0原文

我正在使用带有 ListView 的过滤器,该列表视图通过包含姓名和号码的联系人数据进行填充。

现在,当我在 EditText 中输入文本时,我遇到了两个问题,这又会触发 adapter.getFilter().filter(s.toString())

1)当我稍后输入“aa”时(在我的代码中)

我可以看到以“aa”开头的名称,例如 aakruti ,但在 同时我也可以查看电子邮件地址,这是我不想要的 使其在过滤器被触发时可见。

在此处输入图像描述

2)当我稍后输入“aa”时(在手机的内置联系人列表中)

我可以看到以“aa”开头的名称,例如 aakruti

但我缺少一个名字,即 SATYA(通过联系人显示) 当我在其中输入“aa”时进行搜索)

在此处输入图像描述

这是我的过滤器查询,位于 runQueryOnBackgroundThread 内

StringBuilder buffer = null;
String[] args = null;
    if (constraint != null) {
    buffer = new StringBuilder();
    buffer.append("UPPER(");
    buffer.append(ContactsContract.Contacts.DISPLAY_NAME);
    buffer.append(") GLOB ?");
    args = new String[] { constraint.toString().toUpperCase() + "*" };
    }
String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
System.out.println(buffer);
return mContent.query(
            ContactsContract.Contacts.CONTENT_URI, 
            projection,
            buffer == null ? null : buffer.toString(), 
            args,sortOrder
);

投影数据

   public static String[] projection = new String[] {
           ContactsContract.Contacts._ID,
           ContactsContract.Contacts.DISPLAY_NAME

   };

编辑

到目前为止,我尝试访问

ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME
ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME
ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME
ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME

但 GIVEN_NAME 也显示了一些电子邮件地址,甚至还显示了包含电子邮件地址的联系人姓名 >

对于例如,

[email protected] 
Raul Jakson          (which only has email address no contact number)
Raul Jakson          ( i see this name twice as it has two different email address , but i wanna see it as name )

谁能告诉我如何限制电子邮件地址并仅显示仅包含联系电话号码的姓名?

I am using Filter with ListView which is populated trough Contact data which contains Names and Number.

Now i got two problems when i type a text into EditText which in turns fires adapter.getFilter().filter(s.toString())

1) When i type 'aa' latter (in my code )

i can see name starting from 'aa' for example aakruti , but at the
same time i am able to view email addresses too , which i don't wanted
to make it visible when a filter is fired.

enter image description here

2) When i type 'aa' latter (in phone's inbuilt contact list)

i can see name starting from 'aa' for example aakruti

but i am missing one name i.e. S A T Y A ( which is shown by contact
search when i type 'aa' latter into it )

enter image description here

here is my filter query , inside runQueryOnBackgroundThread

StringBuilder buffer = null;
String[] args = null;
    if (constraint != null) {
    buffer = new StringBuilder();
    buffer.append("UPPER(");
    buffer.append(ContactsContract.Contacts.DISPLAY_NAME);
    buffer.append(") GLOB ?");
    args = new String[] { constraint.toString().toUpperCase() + "*" };
    }
String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
System.out.println(buffer);
return mContent.query(
            ContactsContract.Contacts.CONTENT_URI, 
            projection,
            buffer == null ? null : buffer.toString(), 
            args,sortOrder
);

projection data

   public static String[] projection = new String[] {
           ContactsContract.Contacts._ID,
           ContactsContract.Contacts.DISPLAY_NAME

   };

EDIT

So far i tried to access

ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME
ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME
ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME
ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME

But GIVEN_NAME displays few email address too and even it shows contact name which has email address

for example ,

[email protected] 
Raul Jakson          (which only has email address no contact number)
Raul Jakson          ( i see this name twice as it has two different email address , but i wanna see it as name )

so can anyone tell me how can i limit the email addresses and show only NAMES which has only contact phone numbers ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

缱绻入梦 2025-01-14 02:54:08

首先,电子邮件出现是因为该联系人没有姓名。在这些情况下,Android 将使用电子邮件作为显示名称。为了避免显示这些内容,请使用 GIVEN_NAME 和 FAMILY_NAME。请参阅 StructuredName 的 API 文档

其次,您找不到 SATIYA,因为您的查询正在查找以 AA 开头的 DISPLAY_NAME。 SATIYA 不是一个单词,而是一个首字母缩写序列,例如 SATIY A。如果您想找到这些,那么您必须精心设计查询来满足此要求。您可以搜索 *A*A*,但您也可能会得到许多其他搜索结果。我怀疑 Android 正在执行首字母+姓氏搜索的某种变体,其中 BO 会找到巴拉克·奥巴马 (Barack Obama)。

Firstly, the emails show up because that contact has no name. In these cases, Android will use the email as the display name. To avoid showing these, use GIVEN_NAME and FAMILY_NAME. See the api docs for StructuredName.

Secondly, you don't find SATIYA as your query is looking for a DISPLAY_NAME that begins with AA. SATIYA is not a word, it's a sequence of initials, e.g. S A T I Y A. If you want to find these, then you'll have to craft your query to cater for this. You could search for *A*A*, but you'll probably get many others hits too. I suspect Android is doing some variant of an initial+surname search where BO would find Barack Obama.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文