список контактов Android - PullRequest
0 голосов
/ 24 марта 2011

Хотелось бы получить контакты, созданные с помощью приложения контактов в эмуляторе, и отобразить их как список контактов. Что-то не так?

макет

<?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 голосов
/ 24 марта 2011

Я думаю, вам нужно добавить разрешение в ваш файл манифеста для доступа к контактам.

...