I am working an android project and I am trying to make use of the the AutoCompleteEditText and bind the ArrayAdapter of the contacts. But I am having an issue returning an array of contacts.
Below is the code I am using to retrieve the contacts and display name.
public ArrayList<String> getPhoneNumbersAndContactNames()
{
ArrayList<String> contacts = new ArrayList<String>();
try
{
ContentResolver contentResolver = context.getContentResolver();
Uri uri = Data.CONTENT_URI;
String[] projection = new String[] {PhoneLookup._ID, PhoneLookup.DISPLAY_NAME, PhoneLookup.NUMBER};
String selection = "*";
Cursor cursor = contentResolver.query(uri, projection, selection, null, null);
if (cursor.moveToFirst())
{
contacts.add(cursor.getString(cursor.getColumnIndexOrThrow(PhoneLookup.DISPLAY_NAME)));
}
}
catch (SQLiteException ex)
{
Log.d("Database All Contacts Exception", ex.toString());
}
catch (Exception ex)
{
Log.d("Get All Contacts Exception", ex.toString());
}
return contacts;
}
In the code above I am getting the exception:
IllegalArgumentException: Invalid column number
Below is how I am trying to bind the array list to the auto complete edit text.
txtPhoneNumberOrContact = (AutoCompleteTextView)findViewById(R.id.call_blacklist_txtPhoneNumberContactName);
ArrayList<String> contacts = common.getPhoneNumbersAndContactNames();
ArrayAdapter<String> contactAdapter =
new ArrayAdapter<String>(this, android.R.layout.simple_list_item_activated_1,
contacts);
txtPhoneNumberOrContact.setAdapter(contactAdapter);
I can't figure out why I am getting the exception when trying to retrieve the list of contacts to add to the ArrayList.
Thanks for any help you can provide.