Contact list

Discussion in 'Application Development' started by Costa, May 16, 2009.

  1. Costa

    Costa Active Member
    15

    Apr 18, 2009
    30
    0
    15
    Portugal
    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
    15

    Apr 18, 2009
    30
    0
    15
    Portugal
    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
    15

    May 27, 2009
    7
    0
    15
    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
    5

    May 3, 2010
    1
    0
    5
    import android.R;
     
  5. cmh0114

    cmh0114 Well-Known Member
    36

    Jan 10, 2010
    116
    7
    36
    How would you extract phone numbers, names, or addresses using this code?
     

Share This Page

Loading...