• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps contact list to listview

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);
}
}
}
 
To do it in a listview you must:
1. Edit your main.xml file to insert a ListView
2. Create a new xml file whitch will be the list item
3. Edit you OleContactsActivity.java file and instead of extending Activity, it must extend ListActivity.
4. Create a SimpleCursorAdapter and assign it to the listview.

Search on google for tutorials on ListViews.
 
Back
Top Bottom