android联系人列表

时间:2011-03-24 02:19:24

标签: android contact

想要在模拟器中使用联系人应用创建联系人,并像联系人列表一样显示 有什么不对吗?

布局

<?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"
    >
    <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="Name: "
    />
    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/contact_name"/>
</LinearLayout>

package fypj.e;

import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.widget.*;

public class e extends ListActivity {
    private SimpleCursorAdapter myAdapter;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);
        Cursor cursor = getContentResolver().query(People.CONTENT_URI, null, null, null, null);
        startManagingCursor(cursor);

        String[] column = new String[] {Phone.LABEL};
        int[] names = new int[] {R.id.contact_name};
        myAdapter = new SimpleCursorAdapter(this, R.layout.main, cursor, column, names);
        setListAdapter(myAdapter);
    }
}

1 个答案:

答案 0 :(得分:0)

我认为您需要为清单文件添加权限才能访问联系人。