I have a listview which contains ImageView i. Now I have an array list which contains URLS inside it like www.abc.jpg, www.def.jpg and so on. Now I want to insert these URLs as the source for the image view. Is it possible.?
Asked
Active
Viewed 441 times
2 Answers
0
ImageView
doesn't have any API that allows setting of urls that will be downloaded later on. You need to separately from the ImageView
setup an asynchronous task that will download this image from the url, convert it to a Bitmap
and then set it on ImageView
with setImageBitmap(Bitmap)
.

Maciej Pigulski
- 1,562
- 12
- 26
-
How to set up the Asynchronous task.? – Aishvarya Jaiswal Sep 23 '14 at 09:43
-
http://stackoverflow.com/questions/18953632/how-to-set-image-from-url-for-imageview check this link – Pawan asati Sep 23 '14 at 09:45
-
There are many libraries for Android out there that can help you with that like RoboSpice, Retrofit, Volley and others. If you wish to download it manually then http://developer.android.com/reference/android/os/AsyncTask.html is a maybe not perfect but good enough solution. – Maciej Pigulski Sep 23 '14 at 09:46
-
Please see the updated question. I tried and I am getting network on main thread exception. – Aishvarya Jaiswal Sep 23 '14 at 10:32
0
As noted, you're doing network I/O in the main thread. The stack trace identifies it as happening in onPostExecute. In there, I see this code:
BitmapFactory.decodeStream(newurl.openConnection() .getInputStream()
That certainly looks like network I/O to me.
What I'm wondering is, you've got this lovely worker thread already, but you're doing a lot of work in onPostExecute() (main thread). To prevent janky UI, I suggest you move as much of that computation into doInBackgroud() as possible.

Sparky
- 8,437
- 1
- 29
- 41