如何在 android 2.1 中使用联系人姓名填充 AutoCompleteTextView
我有一个 AutoCompleteTextView,我希望它在输入时自动完成联系人姓名。问题是 Contacts.People 已被弃用。新文档说使用 ContactsContract 但我找不到任何合适的教程。任何人都可以给我一个示例代码或向我指出适当的教程。
谢谢。
I have an AutoCompleteTextView and i want it to autocomplete contact names on input. The problem is that Contacts.People has been deprecated. The new documentation says to use ContactsContract but i can't find any proper tutorial. Can anyone give me a sample code or point me to an appropriate tutorial.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Android Contact API For 2.0
授予访问权限
在应用程序可以查询联系人记录之前,必须通过存储在项目根目录中的 AndroidManifest.xml 文件授予访问权限。在uses-sdk语句下面添加以下uses-permission。
查询 Android 联系人数据库
检索联系人详细信息
基本联系人信息存储在联系人表中,详细信息存储在各个表中以进行规范化。在Android 2.0中,查询基本联系人记录的URI存储在ContactsContract.Contacts.CONTENT_URI中。
包higherpass.TestContacts;
该应用程序与任何其他 Android 应用程序一样启动。首先在cr中创建一个
ContentResolver
实例。然后使用ContentResolver
实例查询数据库并返回包含联系人列表的Cursor
。该查询是针对ContactsContract.Contacts.CONTENT_URI
中存储的 URI 执行的。接下来检查光标是否包含记录,如果包含则循环遍历它们。记录 ID 字段存储在 id 变量中。稍后它将用作where
参数。显示名称字段也存储在字符串名称中。详细了解使用 Android 联系人
Android Contact API For 2.0
Granting Access
Before an application can query the contact records access must be granted through the AndroidManifest.xml file stored in the root of the project. Add the following uses-permission belows the uses-sdk statement.
Querying The Android Contact Database
Retrieving Contact Details
Basic contact information stored in Contacts table with detailed information stored in individual tables for normalization. In Android 2.0 to query the base contact records the URI to query is stored in ContactsContract.Contacts.CONTENT_URI.
package higherpass.TestContacts;
This application starts off as any other Android application. First create a
ContentResolver
instance in cr. Then use theContentResolver
instance to query the database and return aCursor
with the contacts list. The query is performed against the URI stored inContactsContract.Contacts.CONTENT_URI
. Next check if the cursor contains records and if so loop through them. The record ID field is stored in the id variable. This will be used as awhere
parameter later. Also the display name field is stored in the string name.Read more about Working With Android Contacts