English 中文(简体)
安乐;我只有2个接触点,但我能从询问中获得5个联系,为什么?
原标题:Android; I only have 2 contacts, yet I can obtain 5 from a query, why?

我在我的支持者中建立了2个测试接触。

我现在要回答以下提问:它应当把他们从外带走,把我的田野填入,并增加一份清单。 因此,底部的产出应当是2,但这是5,为什么? (保险人.getCount()为5而不是2)

我已经通过每张路程,并且正在多次重新调整同样的接触,但对于<代码>POSTCODE<<>>条码/代码”有不同的价值,例如电话号码。

ContentResolver cr = getContentResolver();
        Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
                null, null, null, null);
        List<MeCercanaContact> contacts = new ArrayList<MeCercanaContact>();
        if (cursor.getCount() > 0)
        {
            while (cursor.moveToNext())
            {
                MyContact myContact = new MyContact();
                String givenName = cursor.getString(cursor.getColumnIndex(
                        ContactsContract.Contacts.DISPLAY_NAME));
                String postcode = cursor.getString(cursor.getColumnIndex(
                        ContactsContract.CommonDataKinds.StructuredPostal.POSTCODE));
                myContact.setFirstName(givenName);
                myContact.setLastName(postcode);
                contacts.add(myContact);
            }
        }
        System.out.println(contacts.size());
最佳回答

您正在询问联系人。 数据是一个通用的集装箱,拥有各种联系细节清单,例如电话号码、邮政编码等。 你们必须为其联系人所在的各行过滤结果。 数据。 页: 1 2. 结构结构: 特定类型:

因此,将问题改为:

Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
     null, null, ContacsContract.Data.MIMETYPE +  "= " + 
ContactsContract.StructuredPostal.CONTENT_ITEM_TYPE + " ", null);

。 数据

问题回答

在AP 21之后,我们撰写了这份关于删除重复联系的书状。

String select = ContactsContract.Data.HAS_PHONE_NUMBER + " != 0 AND " + 
ContactsContract.Data.MIMETYPE
                + " = " + ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + " 
AND "+ ContactsContract.Data.RAW_CONTACT_ID + " = " + 
ContactsContract.Data.NAME_RAW_CONTACT_ID;

Cursor cursor = mContent.query(ContactsContract.Data.CONTENT_URI, null, select, 
 null, null);

a contact that is registered to multiple groups will show up multiple times if you query the Uri CONTENT_URI = ContactsContract.Data.CONTENT_URI

增加以下职位:

 + ContactsContract.Data.DATA1 + " = 1 " ;  //show only contacts in group 1




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签