光标对应每个联系人一个电话号码
我知道如何在光标中获取联系人姓名和号码,但是当我将它们放在列表视图上时,我会在不同的行中获得同一联系人的多个号码,即,如果联系人有多个号码,则会显示所有这些号码。如何为每个联系人仅选择一个号码?
Uri uri = Phone.CONTENT_URI;
String[] projection = { Phone.DISPLAY_NAME, Phone.NUMBER, Phone._ID };
String sortOrder = Phone.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
Cursor cursor = managedQuery(uri, projection, null, null, sortOrder);
感谢您提前提供任何帮助!
I know how to get contact names and numbers in a cursor, but when I put them on a listview I get multiple numbers for the same contact in separate lines, i.e. if a contact has more than one number, all these numbers are displayed. How can I select only one number for each contact?
Uri uri = Phone.CONTENT_URI;
String[] projection = { Phone.DISPLAY_NAME, Phone.NUMBER, Phone._ID };
String sortOrder = Phone.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
Cursor cursor = managedQuery(uri, projection, null, null, sortOrder);
Thanks for any help in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我没猜错,并且您只想为每个
DISPLAY_NAME
显示一个数字,而忽略所有其他数字,则可以使用以下技巧:编辑 简短说明:这是一种 sql 注入:它将在查询的
WHERE
部分插入 1,使其始终为 true,并添加GROUP BY
,managementQuery()
不支持If I got you right, and you want to show only one number per
DISPLAY_NAME
disregarding all others, you can use this hack:edit Short explanation: it's kind of sql-injection: it will insert 1 in
WHERE
part of the query, making it always true, and addGROUP BY
, unsupported bymanagedQuery()