Home » Android » Double Contacts in ListView

Double Contacts in ListView

Posted by: admin November 1, 2017 Leave a comment


I have searched the solution for my problem but couldn’t find a suitable one. I query display name, phone number and thumbnail Uri from ContactsContract Database and put them in a List View through a custom array adapter. But all the contacts are listed as double entry (one with phone number with breaks in it and one without any break.)

For Example: Carlos: +31 111 111 11 and Carlos: +3111111111

Is there a solution that I prevent double entries so that all contacts are listed only one time? I thought of using DISTINCT SQL statement with query but I just found out that DISTINCT can’t be used within CursorLoader. I’d greatly appreciate your opinions.


mProjection = new String[]{ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.Contacts.PHOTO_THUMBNAIL_URI};

public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
    return new CursorLoader(getActivity(), ContactsContract.CommonDataKinds.Phone.CONTENT_URI, mProjection, null, null, null);

public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    mCursor = cursor;

    mContactName = mCursor.getString(mCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME););
    mContactsNumber = mCursor.getString(mCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER););
    mThumbNailUri = mCursor.getString(mCursor.getColumnIndex(ContactsContract.Contacts.PHOTO_THUMBNAIL_URI););

    personDataList.add(new PersonData(mContactName, mContactsNumber, mThumbNailUri, 50, "01"));