无法在android中显示来自联系人的姓名和照片

时间:2016-04-29 12:44:23

标签: android

我目前正在尝试显示来自我的Android设备的联系人的姓名和照片列表,所以我试图使用SimpleCursorAdapter进行显示。我能够在列表视图中显示名称和电话,但是,我无法将照片显示到imageview,有没有办法显示图像列表而不使用下面的代码定制适配器?由于我是Android新手,我很乐意收到你的来信!

 ContentResolver cr = getContentResolver();
        resolver = this.getContentResolver();
        listView = (ListView) findViewById(R.id.lvContacts);

        // Read Contacts
        Cursor c = cr.query(ContactsContract.Contacts.CONTENT_URI,
                new String[]{ContactsContract.Contacts._ID,
                        ContactsContract.Contacts.DISPLAY_NAME}, null, null,
                null);

        // Attached with cursor with Adapter
        mAdapter = new SimpleCursorAdapter(this, R.layout.contact_item, c,
                new String[] { ContactsContract.Contacts.DISPLAY_NAME },
                new int[] { R.id.lblName });

        //for using the imageView
        mAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
                                   @Override
                                   public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
                                       if (view.getId() == R.id.mephoto) {
                                           ImageView IV = (ImageView) view;
//I was thinking about displaying the photos from the contacts
                                           return true;
                                       }
                                       return false;
                                   }
                               }
        );
        listView.setAdapter(mAdapter);

0 个答案:

没有答案