Show Urls Instead Of Images Android App
Solution 1:
You're only fetching the URLs at this point. You need to fetch the actual Bitmap data in order to show images. There are two ways to do this:
- Download all the images, then show the list after everything is fetched
- Show the list immediately with image placeholders, the fetch the images as they're needed
In general, it's a better experience to respond quickly by showing what you have as you get it (option #2). A ListView is really conducive to this model. In the getView() method of the adapter you'll show the placeholder image while firing off an AsyncTask to get the bitmap. You'll then set Image in onPostExecute. Unfortunately things get messy with View recycling. This basic implementation will result in the wrong image being shown in many cases and a totally unresponsive device if the user scrolls back and forth quickly.
Fortunately, these are problems that others have solved. In fact, there is an excellent set of tutorials along with sample code on Android Developer website.
Solution 2:
I have done something like this:
I have a DB
with ID
, image URL
, image URI
image URI
is something like file:////mnt/sdcard/<your package>/images/image1.png
I have a place Holder image for each row and in my Arraylist
i have put image URI
in Arraylist
. then in getView
method check if that URI file
exists or not if not then send a broadcast to download that image(with ID). In downloader I fetch images with corresponding URL.
How to check URI exists: create a file object with URI and call isExists()
How to send broadcast: create an intent
put ID
in extras
then call sendBroadcast(intent)
Now how to refresh list after image has been download: Send another broadcast
from onPostExecute()
to refresh list and catch that broadcast
in your activity
and call list.notifyDatasetChanged()
.
Solution 3:
You are adding String to the list
String bla = div.absUrl("src");
list.add(bla);
You need to create custom adapter
(for the ListView
), which will take that String bla
and download the image.
Try this tutorial
Post a Comment for "Show Urls Instead Of Images Android App"