在 Android 上使用文本框搜索联系人(就像在彩信应用程序中一样)

发布于 2024-10-08 12:18:56 字数 741 浏览 0 评论 0原文

我正在尝试创建一个文本框,允许您开始输入联系人的姓名,并显示手机中联系人的下拉菜单,其姓名与您输入的几个字母相匹配。

(基本上,我是尝试克隆“撰写新消息”屏幕上显示的 MMS.apk 应用程序中的收件人框)

我一直在尝试使用 AutoCompleteTextView 来执行此操作。我已经让它与预先编写的字符串数组一起工作,按照 Android 开发人员网站上的示例。但是,我不确定如何让它搜索我的联系人。

我尝试对整个联系人数据库进行查询,并构建数据库中每个联系人的列表。然而,这需要一段时间,因为要建立手机中每个联系人的列表。当我这样做时,我也无法让下拉建议出现。

有没有更好的方法在手机上搜索联系人?或者有什么真正有效的方法吗?顺便说一句,我使用的是 Android 2.1 API,因此应该使用 ContactsContact 而不是 People。

到目前为止我所做的源代码可以在这里看到: https://code.google.com/p/webtextr/source/browse/trunk/Webtextr/src/com/nomcode/webtextr/MainActivity.java?r =8

任何帮助将非常感激! :)

I'm trying to make a text box that allows you to begin typing the name of a contact, and shows a drop down menu of contacts in your phone whose names match the few letters you've typed in.

(Basically, I'm trying to clone the recipients box in the MMS.apk app that appears on the Compose new message screen)

I've been trying to use an AutoCompleteTextView to do this. I've got it working with a pre-written String array, as per the example on the Android developer site. However, I'm not sure how to get it to search my contacts.

I tried doing a query of the entire database of contacts, and building a List of every contact in the database. However, this takes a while, what with building a List of every contact in the phone. I also can't get the drop down suggestions thing to appear when doing it this way.

Is there a better way to do this searching of contacts on a phone? Or any way at all that actually works? Btw, I'm using the Android 2.1 API, so ContactsContact should be used instead of People.

The source code for what I've done so far can be seen here: https://code.google.com/p/webtextr/source/browse/trunk/Webtextr/src/com/nomcode/webtextr/MainActivity.java?r=8

Any help would be greatly appreciated! :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

就是爱搞怪 2024-10-15 12:18:56

在从 ContactsContract 内容提供程序获取的 Cursor 上使用 CursorAdapter。这将节省您将所有数据转换为 POJO 的时间。

Use a CursorAdapter on the Cursor you obtain from the ContactsContract content provider. That will save you converting all that data into POJOs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文