Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 活动中未显示联系人_Java_Android_Listview - Fatal编程技术网

Java 活动中未显示联系人

Java 活动中未显示联系人,java,android,listview,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_paren

我试图在活动中显示联系人,但它不起作用。 我检查了代码,但无法理解问题所在。 这是我的密码:-

/删除/

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>

将代码更改为:

// 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);

您没有将光标传递给
SimpleCorsOrAdapter

使用光标获取移动联系人

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));

        }