Click here to Skip to main content
14,924,531 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have code to display contacts but i have find difficult to display contacts after @ symbol ..Kindly Help...
public class AutoCompleteTextViewActivity extends Activity {
String[] result;
String[] datacols = new String[]{
ContactsContract.CommonDataKinds.Phone._ID,
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER,};

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

loadingContacts();

}


public void loadingContacts() {

ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, datacols,
null, null, null);
startManagingCursor(cursor);
int count = cursor.getCount();
result = new String[count];

int contact_name = cursor
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
int contact_number = cursor
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);

int i;
long temp;
for (cursor.moveToFirst(), i = 0; !cursor.isAfterLast() && i < count; cursor
.moveToNext(), i++) {
temp = cursor.getLong(contact_number);
result[i] = cursor.getString(contact_name) + "\n" + temp;
}

ArrayAdapter<string> adapter = new ArrayAdapter<string>(this,
android.R.layout.simple_dropdown_item_1line, result);
AutoCompleteTextView textView = (AutoCompleteTextView)
findViewById(R.id.txtCountries);
textView.setThreshold(0);
textView.setAdapter(adapter);



}



}
Posted
Comments
Richard MacCutchan 17-Feb-15 11:54am
   
Pleas edit your post, format your code properly and add some detail about where the problem occurs.

1 solution

Implement TextChanged listener and set your Adapter in OnTextChange method.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900