1. 2015 is going to be a great year for Android! Why wait??
    Samsung Galaxy Note 5 | Samsung Galaxy S6 | HTC One M9
  2. New Forum Created: Samsung Gear VR!

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:
    public class ContactList extends Activity {
            
        @Override
        public void onCreate(Bundle icicle) {
            super.onCreate(icicle);
            setContentView(R.layout.contactlist);
            
            final Cursor c = managedQuery(People.CONTENT_URI, null, null, null, null);
            String[] from = new String[] {People.NAME};
            int[] to = new int[] { R.id.text_view };
            SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,R.layout.contactlist,c,from,to);
            ListView lv = (ListView)findViewById(R.id.list_view);
            lv.setAdapter(adapter);
        }
    }
    contactlist.xml
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
        <ListView
        android:id="@+id/list_view"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        />
        <TextView
        android:id="@+id/text_view"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        />
    </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,509
  2. Fish
    Replies:
    0
    Views:
    2,123
  3. doni2670
    Replies:
    2
    Views:
    961

Share This Page