开发者

Search Contacts on Android with text box (like in MMS app)

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! :)开发者_运维百科


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜