Praveen Praveen - 1 year ago 146
Android Question

Get the Email from Contacts using AutoComplete TextView?

In my application i've one

AutoComplete TextView
In this
AutoComplete TextView
provides all the contact names from Contacts.

I want to get the primary email id which contact was selected in my AutoComplete Textview to the editText. How can i achieve this? Anyone guide me?

Answer Source

Make sure you have READ_CONTACTS permission for your App.

    AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView)findViewById(;
    Cursor emailCursor = getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, null, null, null);
    autoCompleteTextView.setAdapter(new SimpleCursorAdapter(this, android.R.layout.simple_dropdown_item_1line, emailCursor, new String[] {Email.DATA1}, new int[] {}));

Please Note AutoCompleteTextView is Case Sensitive.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download