I have a listview
with CompoundDrawable
, the images in the compound drawable
need to be loaded from the web.
How can i load images to CompoundDrawable
from the URL.
i think that i can get bitmap image from the URL convert it into Drawable and then load it into the CompoundDrawable. like this
public static Drawable drawableFromUrl(String url) throws IOException {
Bitmap x;
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.connect();
InputStream input = connection.getInputStream();
x = BitmapFactory.decodeStream(input);
return new BitmapDrawable(x);
}
is there a better way to do it? can i do it directly without geting bitmap from URL and then converting bitmap to drawable?