联系人未在活动中显示

时间:2015-05-29 10:14:08

标签: java android listview

我试图在活动中显示联系人,但它无效。 我查看了我的代码,但无法理解问题是什么。 这是我的代码: -

/ 删除 /

showfriendlist.xml

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <ListView
            android:id="@+id/lst_contacts"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </RelativeLayout>

2 个答案:

答案 0 :(得分:0)

将您的代码更改为:

// The contacts from the contacts content provider is stored in this cursor
    mMatrixCursor = new MatrixCursor(new String[]{"_id", "name", "photo", "details"});

// Adapter to set data in the listview
    mAdapter = new SimpleCursorAdapter(getBaseContext(),
            R.layout.lv_layout,
            mMatrixCursor,
            new String[]{"name", "photo", "details"},
            new int[]{R.id.tv_name, R.id.iv_photo, R.id.tv_details}, 0);

您没有将光标传递给SimpleCursorAdapter

答案 1 :(得分:0)

使用光标获取移动联系人

Cursor c = getContentResolver().query(Phone.CONTENT_URI, null,
                null, null, Phone.DISPLAY_NAME + " ASC");

        while (c.moveToNext()) {

            contactName = c
                    .getString(c
                            .getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
            phNumber = c
                    .getString(c
                            .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

        }
相关问题