I am trying to display the profile image from a twitter list. I have a listview being used with Async task. My ImageView is being done dynamically in a drawable from the URL. It seems to work fine on the 2.3.3, but the image does not show on 4.0. I ImageView has to work on 4.0. I’m puzzled.
Here is from my adapter:
Tweet o = tweets.get(position);
Drawable drawable = LoadImageFromUrl.LoadImageFromWebOperations(o.profile_image_url);
image.setImageDrawable(drawable);
The method that converts to URL to drawable is this:
public static Drawable LoadImageFromWebOperations(String url) {
try {
Log.i("URL", url);
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
} catch (Exception e) {
return null;
}
}
And my xml layout for my list items (tweets)is here:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dip" xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:id="@+id/profile_image"
android:layout_width="48dip"
android:layout_height="48dip"
android:layout_gravity="top|left"
android:layout_margin="6dip"
android:contentDescription="Profile Image"
android:src="@drawable/ic_launcher"/>
<!-- Name -->
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/profile_image"
android:paddingBottom="1dip"
android:textColor="#0598DD"
android:textSize="14dip"
android:textStyle="bold" />
<!-- Screen name -->
<TextView
android:id="@+id/screen_name"
android:layout_below="@id/profile_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/name"
android:paddingBottom="1dip"
android:textColor="#ffffff"
android:textSize="14dip"
android:textStyle="italic" />
<!-- Tweet -->
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/name"
android:paddingBottom="1dip"
android:textColor="#ffffff"
android:textSize="16dip"
android:textStyle="bold" />
<!-- date -->
<TextView
android:id="@+id/time_stamp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/text"
android:paddingBottom="3dip"
android:textColor="#0598DD"
android:textSize="14dip"
android:textStyle="italic" />
</RelativeLayout>
Nobody responded. I fixed this by using the UrlImageViewHelper: