• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Contact list

Costa

Newbie
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!
 
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
 
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.
 
Back
Top Bottom