1. Download our Official Android App: Forums for Android!

Apps Contact list

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

  1. Costa

    Costa Member
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    30
    Joined:
    Apr 18, 2009

    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 Member
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    30
    Joined:
    Apr 18, 2009

    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 Lurker
    Rank:
    None
    Points:
    25
    Posts:
    7
    Joined:
    May 27, 2009

    May 27, 2009
    7
    0
    25
    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 Lurker
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    May 3, 2010

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

    ganeshpisal Newbie
    Rank:
    None
    Points:
    15
    Posts:
    14
    Joined:
    Jun 2, 2010

    Jun 2, 2010
    14
    0
    15
  6. cmh0114

    cmh0114 Well-Known Member
    Rank:
    None
    Points:
    36
    Posts:
    114
    Joined:
    Jan 10, 2010

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

Share This Page

Loading...