Ya, sure.Here is my code:
String[] phonesProjection = new String[] {Contacts.People.Phones.NUMBER, Contacts.People.Phones.TYPE,Contacts.People.Phones.DISPLAY_NAME,
Contacts.People.Phones._ID,Contacts.People.Phones.LABEL };
Cursor phonesCursor = content.query(Contacts.Phones.CONTENT_URI, phonesProjection, null, null, null);
ContactListAdapter adapter = new ContactListAdapter(this, phonesCursor);
AutoCompleteTextView textView = (AutoCompleteTextView)
findViewById(R.id.edit);
textView.setAdapter(adapter);
public static class ContactListAdapter extends CursorAdapter implements Filterable {
public ContactListAdapter(Context context, Cursor c) {
super(context, c);
mContent = context.getContentResolver();
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
final LayoutInflater inflater = LayoutInflater.from(context);
final TextView view = (TextView) inflater.inflate(
android.R.layout.simple_dropdown_item_1line, parent, false);
Log.i("Cursor Count",""+cursor.getCount());
view.setText(cursor.getString(2)+" "+cursor.getString(0));
return view;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
((TextView) view).setText(cursor.getString(2)+" "+cursor.getString(0));
}
@Override
public String convertToString(Cursor cursor) {
return "";
}
@Override
public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
if (getFilterQueryProvider() != null) {
return getFilterQueryProvider().runQuery(constraint);
}
StringBuilder buffer = null;
String[] args = null;
if (constraint != null) {
buffer = new StringBuilder();
buffer.append("UPPER(");
buffer.append(Contacts.People.Phones.DISPLAY_NAME);
buffer.append(") GLOB ?");
args = new String[] { constraint.toString().toUpperCase() + "*" };
}
String[] phonesProjection = new String[] {Contacts.People.Phones.NUMBER, Contacts.People.Phones.TYPE,Contacts.People.Phones.DISPLAY_NAME,
Contacts.People.Phones._ID,Contacts.People.Phones.LABEL };
Cursor phonesCursor = mContent.query(Contacts.Phones.CONTENT_URI, phonesProjection, null, null,Contacts.People.Phones.DEFAULT_SORT_ORDER);
int phonesCursorCount = phonesCursor.getCount();
System.out.println("phonesCursorCount="+phonesCursorCount);
return phonesCursor;
}
private ContentResolver mContent;
}