문제

I built a contact list and I'm trying to add the contact's photos to it, I managed to get a Contact PHOTO_THUMBNAIL_DATA but I cannot figure how to load it to an ImageView.

ImageView imgView = (ImageView) itemLayout.findViewById(android.R.id.icon);
final String photoUri = cursor.getString(ContactsQuery.PHOTO_THUMBNAIL_DATA);

How can this be done?

도움이 되었습니까?

해결책

you need to use ImageView.setImageURI()

public void setImageURI (Uri uri)

Sets the content of this ImageView to the specified Uri.

This does Bitmap reading and decoding on the UI thread, which can cause a latency hiccup. If that's a concern, consider using setImageDrawable(android.graphics.drawable.Drawable) or setImageBitmap(android.graphics.Bitmap) and BitmapFactory instead.

for example

String uri = cursor.getString(cursor.getColumnIndex(Contacts.PHOTO_THUMBNAIL_URI));
if (uri != null) {
    Uri photoUri = Uri.parse(uri);
    iv_object_contact.setImageURI(photoUri);
}
else {
    iv_object_contact.setImageResource(res_default_contact);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top