Peter Peter - 18 days ago 4x
Android Question

AutoCompleteTextView with SimpleCursorAdapter for Contacts not returning cursor actual value

I have a AutoCompleteTextView that uses a SimpleCursorAdapter to filter emails for an input field. I have it working, although there are some

commands that I am not sure how to rework.

The only problem I am having is when I select a value from the list provided, I am not getting the email address selected, but something like the following:


Here is the code I have:

final AutoCompleteTextView edt_Contact = (AutoCompleteTextView)findViewById(idTo);

ContentResolver cr = getContentResolver();
String[] projection={ContactsContract.CommonDataKinds.Email._ID,ContactsContract.CommonDataKinds.Email.ADDRESS};
Cursor cursor = cr.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, projection, null, null, null);

String[] from = new String[] { ContactsContract.CommonDataKinds.Email.ADDRESS};
int[] to = new int[] {};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, cursor, from, to);

adapter.setFilterQueryProvider(new FilterQueryProvider() {
public Cursor runQuery(CharSequence constraint) {
return getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,
new String[] {},
ContactsContract.CommonDataKinds.Email.ADDRESS + " LIKE '%" + constraint + "%'",
null, null);


Any suggestions on how to get the actual selected value to populate the AutoCompleteTextView when selected?

Also, as mentioned, the depreciated items are


Found the solution and I am posting it here for anyone else with a similar situation

I needed to add the following


I added it right before the last line in the example above. This changed the result from the


to the selected email address.

Just a heads-up too for anyone using the MultiAutoCompleteTextView to do the same thing, this code works for that as well... just change add Multi before the AutoCompleteTextView and add the .setTokenizer of your choice.