Reputation: 633
I have a code similar to this.
And like in there I want to add pictures dynamically to my ListView using a SimpleAdapter, but instead of having the photos on the Drawable resources I want to grab mine from the web. I already have a method that gets a url and returns a Drawable and I want to add the id of that Drawable to the HashMap like he does. How to I get that id (R.drawable.blabla) ?
Btw here's the method
public static Drawable loadImageFromWeb(String url) {
try {
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
} catch (Exception e) {
return null;
}
}
Upvotes: 0
Views: 108
Reputation: 633
Ok, managed to solve the issue with this:
http://www.technotalkative.com/android-asynchronous-image-loading-in-listview/
Very good source, thanks all.
Upvotes: 0
Reputation: 4418
Whatever that guy is doing isn't the best way to go about it, use a https://developer.android.com/reference/android/widget/BaseAdapter.html base adapter and override the getview method
Upvotes: 1
Reputation: 9189
Adding a new Drawable Resource at runtime is not possible. Resource ID's and data are generated while editing and bundled into your APK at build time.
Instead create a local cache and load files from there.
Upvotes: 3