Iām autocompleting the edittext field for contact phone numbers. I know how to get contacts from the database and display them in a text box, but I just need to autocomplete them if the user wants to enter a name in the text box. I understand how to get an array for automatic completion and the whole theory. But how to pull phone contacts is difficult. I saw a lot of tutorials, as well as a different question about stack overflow, but still awkward. The code snippet will help you.
public class MyContacts extends Activity { AutoCompleteTextView txtPhoneNo; public ArrayList<String> c_Name = new ArrayList<String>(); public ArrayList<String> c_Number = new ArrayList<String>(); String[] name_Val = null; String[] phone_Val = null; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); txtPhoneNo = (AutoCompleteTextView) findViewById(R.id.txtPhoneNo); } Uri contacts = Uri.parse("content://icc/adn"); ContentResolver cr = getContentResolver(); Cursor managedCursor1 = cr.query(contacts, null, null, null, null); { if (managedCursor1.moveToFirst()) { String contactname; String cphoneNumber; int nameColumn = managedCursor1.getColumnIndex("name"); int phoneColumn = managedCursor1.getColumnIndex("number"); Log.d("int Name", Integer.toString(nameColumn)); Log.d("int Number", Integer.toString(phoneColumn)); do {
My code ... no compilation errors, but still not working
source share