通过不在android游标中工作的顺序
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.
从上面的行中删除属性名称前的空格。