Contact list


Last Updated:

  1. Costa

    Costa Active Member This Topic's Starter

    Joined:
    Apr 18, 2009
    Messages:
    30
    Likes Received:
    0
    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 This Topic's Starter

    Joined:
    Apr 18, 2009
    Messages:
    30
    Likes Received:
    0
    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

    Joined:
    May 27, 2009
    Messages:
    7
    Likes Received:
    0
    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

    Joined:
    May 3, 2010
    Messages:
    1
    Likes Received:
    0
    import android.R;
     
  5. ganeshpisal

    ganeshpisal Member

    Joined:
    Jun 2, 2010
    Messages:
    14
    Likes Received:
    0
  6. cmh0114

    cmh0114 Well-Known Member

    Joined:
    Jan 10, 2010
    Messages:
    116
    Likes Received:
    7
    How would you extract phone numbers, names, or addresses using this code?
     

Share This Page

Loading...