I had some cursors ti retrieve contacts from Android, all its ok but the problem its i cant make work the "Order by" clause. i tried a lot of things, even using "Upper" and localized collection clauses but seems isnt working, im using a hashmap to store the results, so i guess i will need order the hashmap but i dont want this because order by should solve the problem and save processing time. This is my code:

我有一些游标从Android检索联系人,一切正常,但问题是我不能使工作成为“订购依据”条款。我尝试了很多东西,甚至使用“Upper”和本地化的集合条款,但似乎无法正常工作,我使用hashmap存储结果,所以我想我需要订购hashmap但我不想要这个因为订单应该解决问题并节省处理时间。这是我的代码:

 private Cursor getContacts() {
        // Run query
        Uri uri = ContactsContract.Contacts.CONTENT_URI;
        String[] projection = new String[] { ContactsContract.Contacts._ID,
            ContactsContract.Contacts.DISPLAY_NAME };
        String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '"
            + ("1") + "' AND "+ ContactsContract.Contacts.HAS_PHONE_NUMBER +"='" +("1")+"'";
        String sortOrder =" "+  ContactsContract.Contacts.DISPLAY_NAME +" ASC";

        CursorLoader query = new CursorLoader(context,uri, projection,
                selection, null,
            sortOrder);
        return query.loadInBackground();
      }

and this is other to get contacs by group:

这是另一个按组获得的接触:

contactInfo = new HashMap<String, ContactInfo>();
         Cursor c = context.getApplicationContext().getContentResolver().query(ContactsContract.Data.CONTENT_URI
                , new String[] {
                ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.Contacts._ID, 
                ContactsContract.RawContacts.CONTACT_ID },
                ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID + " = ?"+ " AND "
                + ContactsContract.Contacts.HAS_PHONE_NUMBER +"='" +("1")+"'",
                new String[] { groupId },"UPPER("+ ContactsContract.Contacts.DISPLAY_NAME + ") ASC");

after getting cursor i use the while(c.moveToNext()) code

获取光标后我使用while(c.moveToNext())代码

1 个解决方案

#1


1

Got it worked ,

搞定了,

context.getContentResolver().query(CONTENT_URI, null, buf == null ? null : buf.toString(),args,Cons.ATTRIBUTES_NAME + " ASC");

Without have a space in the orederby string,

没有在orederby字符串中的空格,

=" "+  ContactsContract.Contacts.DISPLAY_NAME +" ASC"

From the above line remove the space before the attribute name.

从上面的行中删除属性名称前的空格。

更多相关文章

  1. javascript去掉前后空格
  2. Java操作ini文件 ,解决properties文件中无法读取换行及空格
  3. Java将一个字符串中的多个连一起的空格变成单个空格

随机推荐

  1. Android进度条总结
  2. android源码在线查看
  3. Android使用代码模拟HOME键的功能
  4. 35、键盘布局的tableLayout备份
  5. Android(安卓)Gallery子元素无法横向填满
  6. Android植物大战僵尸小游戏
  7. android返回HOME界面
  8. android textview部分字体变颜色
  9. android自带图片资源
  10. Android 珍藏(三)