lisovaccaro
lisovaccaro

Reputation: 33996

Get PHOTO_THUMBNAIL_DATA in ImageView?

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?

Upvotes: 0

Views: 146

Answers (1)

Sruit A.Suk
Sruit A.Suk

Reputation: 7273

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

Upvotes: 1

Related Questions