Contact list


  1. Costa

    Costa Active Member

    Hello guys.


    I wanted import the contacts and all their data associated (adress, phone number, etc) to my application.

    Do you guys have any example of code how to do it?

    Cheers!

    Advertisement
    :
  2. Costa

    Costa Active Member

    Anyway, i made it.

    ContactList.java
    Code (Text):
    1. public class ContactList extends Activity {
    2.        
    3.     @Override
    4.     public void onCreate(Bundle icicle) {
    5.         super.onCreate(icicle);
    6.         setContentView(R.layout.contactlist);
    7.        
    8.         final Cursor c = managedQuery(People.CONTENT_URI, null, null, null, null);
    9.         String[] from = new String[] {People.NAME};
    10.         int[] to = new int[] { R.id.text_view };
    11.         SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,R.layout.contactlist,c,from,to);
    12.         ListView lv = (ListView)findViewById(R.id.list_view);
    13.         lv.setAdapter(adapter);
    14.     }
    15. }
    contactlist.xml
    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <LinearLayout
    3. xmlns:android="http://schemas.android.com/apk/res/android"
    4. android:orientation="vertical"
    5. android:layout_width="fill_parent"
    6. android:layout_height="fill_parent">
    7.     <ListView
    8.     android:id="@+id/list_view"
    9.     android:layout_width="fill_parent"
    10.     android:layout_height="wrap_content"
    11.     />
    12.     <TextView
    13.     android:id="@+id/text_view"
    14.     android:layout_width="fill_parent"
    15.     android:layout_height="wrap_content"
    16.     />
    17. </LinearLayout>
    Hope helps someone in future
  3. randheer

    randheer Member

    Is this code working? Its saying "R.layout.contactlist cannot be resolved" and when I copied the xml to main.xml its saying "No grammer constraints detected for this document". Please tell me how to solve this matter.
  4. lucienmathieu

    lucienmathieu New Member

    import android.R;
  5. cmh0114

    cmh0114 Well-Known Member

    How would you extract phone numbers, names, or addresses using this code?
Loading...
Similar Threads
  1. jam-bro
    Replies:
    1
    Views:
    1,572
  2. Fish
    Replies:
    0
    Views:
    2,152
  3. doni2670
    Replies:
    2
    Views:
    982

Share This Page