使用CursorLoader获得接触导致的重复 [英] Using CursorLoader to get contacts causes duplication

查看:165
本文介绍了使用CursorLoader获得接触导致的重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建设,我想填充有电话号码的联系人的活动。

I am building an activity which I want to populate with contacts that have telephone numbers.

我不使用的意图,因为我希望这是我的列表视图每个接触前的复选框。

I am not using an Intent because I want there to be a checkbox before each contact in my listview.

我使用CursorLoader。下面是从onCreateLoader方法有些code;

I am using CursorLoader. Here is some code from the onCreateLoader method;

String projection[] = new String[]{ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME};
    Uri uri = ContactsContract.Data.CONTENT_URI;

    String selection = ContactsContract.Contacts.HAS_PHONE_NUMBER + "=1" + 
    " AND " + ContactsContract.Contacts.IN_VISIBLE_GROUP + " =1";

    String order = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";

    CursorLoader loader = new CursorLoader(this, uri, projection, selection, null, order);

我用ResourceCursorAdapter的子类,我的ListView。

I use a subclass of ResourceCursorAdapter with my ListView.

有没有人有任何想法我如何删除重复?我不想使用一组,除非我真的不得不这样做。

Does anyone have any ideas how I remove the duplicates? I don't want to use a Set unless I really have to.

推荐答案

我会建议查询联系人表,而不是原始的数据表。

I would recommend querying the Contacts table as opposed to the raw Data table.

Uri uri = ContactsContract.Contacts.CONTENT_URI;

在数据表中包含原始联系人数据,这可能意味着多个条目相同的人,因为Android的联系人来自多个不同帐户来源汇总。其他一切都看起来很好。

The data table contains raw contact data, which can mean multiple entries for the same "person" since Android contacts are aggregated from multiple different account sources. Everything else looks fine.

这篇关于使用CursorLoader获得接触导致的重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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