问题描述
我将操纵Android 2.O中的接触组.我的代码如下:
获取组列表(带ID和标题):
final String[] GROUP_PROJECTION = new String[] { ContactsContract.Groups._ID, ContactsContract.Groups.TITLE }; Cursor cursor = ctx.managedQuery(ContactsContract.Groups.CONTENT_URI, GROUP_PROJECTION, null, null, ContactsContract.Groups.TITLE + " ASC");
稍后,在listView上,我选择一个组(OnClick事件),并通过以下代码阅读所有联系人属于此选定的组:
String where = ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID + "=" + groupid + " AND " + ContactsContract.CommonDataKinds.GroupMembership.MIMETYPE + "='" + ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE + "'";
问题:第一个查询中的contactscontract.groups._id与ContactScontract.commondatakinds.groupmembership.group_row_id在第二个查询中不匹配.
任何解决方案/建议?
推荐答案
我与联系人组一起工作了很多,而且我记得那些代码片段的其他帖子.该代码确实对我有用,也应该为您工作.
我不明白为什么两个数据不应该匹配.请再次检查.
问题描述
I would manipulate the contact groups in Android 2.O. My code is following:
To get a list of group (with id and title):
final String[] GROUP_PROJECTION = new String[] { ContactsContract.Groups._ID, ContactsContract.Groups.TITLE }; Cursor cursor = ctx.managedQuery(ContactsContract.Groups.CONTENT_URI, GROUP_PROJECTION, null, null, ContactsContract.Groups.TITLE + " ASC");
Later, on an ListView, I select a group (onClick event) and read all contacts belong to this selected group by following code:
String where = ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID + "=" + groupid + " AND " + ContactsContract.CommonDataKinds.GroupMembership.MIMETYPE + "='" + ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE + "'";
Problem: ContactsContract.Groups._ID in the first query does not match with the ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID in the second query.
Any solution/suggestion?
推荐答案
I worked a lot with Contact Groups, and as I remember those code fragments up there are from my other posts. The code does work for me, and should work for you too.
I don't see why the two data should not match. Please double check again.