Skip to content

Instantly share code, notes, and snippets.

@snadjafi
Created June 3, 2014 00:12
Show Gist options
  • Save snadjafi/8b5c4fa983f9a14b70e5 to your computer and use it in GitHub Desktop.
Save snadjafi/8b5c4fa983f9a14b70e5 to your computer and use it in GitHub Desktop.
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) {
return new CursorLoader(getActivity(),
// Retrieve data rows for the device user's 'profile' contact.
Uri.withAppendedPath(ContactsContract.Profile.CONTENT_URI,
ContactsContract.Contacts.Data.CONTENT_DIRECTORY), ProfileQuery.PROJECTION,
// Select only email addresses.
ContactsContract.Contacts.Data.MIMETYPE +
" = ?", new String[]{ContactsContract.CommonDataKinds.Email
.CONTENT_ITEM_TYPE},
// Show primary email addresses first. Note that there won't be
// a primary email address if the user hasn't specified one.
ContactsContract.Contacts.Data.IS_PRIMARY + " DESC");
}
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
List<String> emails = new ArrayList<String>();
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
emails.add(cursor.getString(ProfileQuery.ADDRESS));
cursor.moveToNext();
}
addEmailsToAutoComplete(emails);
private void addEmailsToAutoComplete(List<String> emailAddressCollection) {
//Create adapter to tell the AutoCompleteTextView what to show in its dropdown list.
ArrayAdapter<String> adapter =
new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_dropdown_item_1line, emailAddressCollection);
mEmailTextView.setAdapter(adapter);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment