thejeraldo
Lurker
hi, im trying to do a contact list using by using a list view.
im able to use the contactcontracts provider and was able to fetch all the contacts from my phone but only through logcat. how do i do this/pass the values i fetch to an array or a listview? thanks. heres my code.
package com.olecontacts.sirje;
import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.PhoneLookup;
import android.util.Log;
public class OleContactsActivity extends Activity{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
Cursor people = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, sortOrder);
//String[] fields = new String[] {ContactsContract.Data.DISPLAY_NAME};
while(people.moveToNext()){
int nameIndex = people.getColumnIndex(PhoneLookup.DISPLAY_NAME);
String name = people.getString(nameIndex);
Log.d("CONTACTS", name);
}
}
}
im able to use the contactcontracts provider and was able to fetch all the contacts from my phone but only through logcat. how do i do this/pass the values i fetch to an array or a listview? thanks. heres my code.
package com.olecontacts.sirje;
import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.PhoneLookup;
import android.util.Log;
public class OleContactsActivity extends Activity{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
Cursor people = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, sortOrder);
//String[] fields = new String[] {ContactsContract.Data.DISPLAY_NAME};
while(people.moveToNext()){
int nameIndex = people.getColumnIndex(PhoneLookup.DISPLAY_NAME);
String name = people.getString(nameIndex);
Log.d("CONTACTS", name);
}
}
}