Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Multiple Contacts Chooser (with option of choosing which phone number)

I need to be able to select multiple contacts in Android. The flow is like this :

  1. User clicks on a button which opens the Contacts application.
  2. However, instead of being able to select a single contact, I need to be able to select multiple contacts (in the same launch of the intent).
  3. If a contact has multiple phone numbers, I need the user to be able to choose which phone number he wants to select.

This feature is already present in my Samsung Android Phone (Running 2.3 Gingerbread) when I click on "Contacts" in the Messaging app. See screenshot below :

enter image description here

enter image description here

enter image description here

like image 575
YD8877 Avatar asked Oct 08 '22 22:10

YD8877


1 Answers

There is not built in way of doing this, so you need to do most of the work by yourself. Luckily, it's not that hard.

Display

To Display your contacts you can use either a listview with the multi-select choice mode, or you can create a custom adapter and bind it to a regular listview. I don't think the listview with multi-select will let you put anything other than text for each row, but you'd have to dig deeper to find out.

I've used the custom adapter method for something very similar (except the multiple phone numbers part). It's pretty easy to do and I find custom adapters are really useful in the long run.

Custom Adapter Listview Tutorial

With a custom adapter setup, you can create data objects with all the information for a person including their Name and Phone Number(s). In the getView of your Custom Adapter, you can decide what/how and where to display each piece of information.

Gathering Information

You'll need to use the ContactContract API to get information for your contacts.

Reading Contact Info

Reading ALL phone numbers for a Contact

like image 178
Gophermofur Avatar answered Oct 12 '22 12:10

Gophermofur