获取所有的联系方式,并显示他们的列表视图他们的、有的、视图、联系方式

2023-09-04 07:09:33 作者:拿命去搏我的未来゜

我显示在列表视图中的所有联系人,这是伟大的工作。但我也想图像添加到列表视图。搜索了很多,但没有发现任何好的教程。请推荐一些教程显示在列表视图接触图像。以下是我的code。

I am showing all contacts in listview and it is working great. But I also want to add image to listview. Searched alot but didn't find any good tutorial. Please suggest some tutorials for showing contact images on listview. Following is my code.

Cursor cur = getContacts();

    ListView lv = getListView();

    String[] fields = new String[] {ContactsContract.Data.DISPLAY_NAME };


    adapter = new SimpleCursorAdapter(this,
            R.layout.contacts_list_row, cur, fields,
            new int[] { R.id.title}, 0);
    lv.setAdapter(adapter);

getContacts()

private Cursor getContacts() {
    // Run query
    Uri uri = ContactsContract.Contacts.CONTENT_URI;

    String[] projection = new String[] { ContactsContract.Contacts._ID,
            ContactsContract.Contacts.DISPLAY_NAME };
    String selection = null;
    String[] selectionArgs = null;
    String sortOrder = ContactsContract.Contacts.DISPLAY_NAME
            + " COLLATE LOCALIZED ASC";
    return managedQuery(uri, projection, selection, selectionArgs,
            sortOrder);
}

在此先感谢:)

Thanks in advance :)

推荐答案

我不知道你会发现如何使用一个简单的适配器添加图像的教程......你可能需要创建一个自定义列表适配器。

I don't know if you will find a tutorial on how to add images with a Simple adapter...you will probably need to create a custom list adapter.

这真的很简单,给你一个很大的灵活性。 试试这个应该给一个体面的起点。

it's really easy and gives you a huge amount of flexibility. try this that should give a decent starting point.

您需要创建一个布局,有一个ImageView的,和名称,然后在适配器可以设置图片和名称等。

You will need to create a layout that has an ImageView, and the name, then in the adapter you can set the images and names etc.