【问题标题】:Contact list not sort in Android联系人列表未在 Android 中排序
【发布时间】:2015-11-23 04:58:04
【问题描述】:

我正在尝试按字母排序顺序获取我的电话联系人。它快速获取名称但没有得到排序顺序。我尝试了 ContactsContract.Contacts.SORT_KEY_PRIMARY + "ASC"ContactsContract .Contacts.DISPLAY_NAME + "ASC" 但效果不佳。

我的代码是

Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null,ContactsContract.Contacts.DISPLAY_NAME + " ASC");
while (phones.moveToNext())
{
    String name=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
    String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
   Log.e("Tag ","Name " + name);

}
phones.close();

【问题讨论】:

    标签: android


    【解决方案1】:

    您必须像这样获取手机联系人的排序顺序:

    int sort_order=Settings.system.getInt (getApplicationContext ().getContentResolver (),"android.contacts.SORT_ORDER");
    

    现在您的光标查询将是这样的:

    Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null,sort_order);
    

    【讨论】:

      【解决方案2】:

      您可以按字母顺序获取联系人:

      Cursor cursor = getContentResolver.query(Phone.CONTENT_URI, null, null, null, Phone.DISPLAY_NAME + " ASC");
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-08-16
        • 2016-01-28
        • 1970-01-01
        • 2010-12-26
        • 1970-01-01
        • 2012-03-12
        • 2021-07-25
        相关资源
        最近更新 更多