I am adding multiple views to my linearlayout dynamically using async task. In the first run images are not loading completely, its loading only 60- 80 % only.
images are fetching through web service and adding dynamically to view. It will load completely only after i go back and come to the page or after taking another page.
please check following image.
all view are adding dynamically. also using progress dialog for async task.
I would advice you to use this Image Loader Library to load those images dynamically with ease. Use a ListView with your own Adapter and add the loading image code there.
Related
I have a listview that load images with a adapter. Every time that I scroll the screen, the listview calls the getView to refresh the listview, then the getView loads a image, doing that in my ui thread, locking my screen for a moment.
What I did was to load the images in a AsyncTask class. But the problem is that it take a little bit, and when you scroll you see the wrong image, after a while it louds the right image. I didn't want to have that problem, showing the wrong image for a moment.
I search and saw that there is no way to stop that listview automatic refresh.
What should I do to resolve that problem? Any tutorial would be helpful.
What should I do to resolve that problem?
Set the ImageView to show a placeholder image in getView(), while you fork the task to load the real image. Or, as others have suggested, use any number of libraries for managing all of that for you (and I echo the Picasso recommendation).
I have a class that extends BaseAdapter, which I use for a ListView. In the getView() method of that class I'm using an AsyncTask with a callback method to download an image (once downloaded, I store it, so I don't have to download it again). When the ListView loads the items first, only the first item displays an image an then starts to change the images (repeatedly displaying the images of the other items). Later also the other items start showing the same behaviour. After a while they stop cycling the images and each item shows the correct images. If I scroll the ListView the items are starting again to cycle the images.
This only happens, if I recycle the convertView parameter, that is passed to getView(). If I don't the images take very long to show up, and I'm afraid I'm creating too much new Views.
Thanks in advance for any advices, to get this working properly.
The simple way to get this going is to dump all your own image loading code and use something that already handles this, like Square's Picasso. There are plenty of alternatives if you do not like Picasso.
Otherwise, your tasks will need to be aware of the recycling, so they do not attempt to update an ImageView that now needs a different image. For example, you could use setTag() and getTag() on the ImageView to store (and retrieve) the URL the ImageView currently needs, and if the image downloaded by the task is some other URL, don't apply it.
But, again, please use an existing library for this. It's 2013: few people should be rolling their own download-the-images-for-use-in-ListView-rows code anymore.
Currently I have implemented Expandable List View referencing from the following website:
http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/
Now, how do I download a jpeg from a url(e.e. h--p://www.test.com/image.jpg) and display this image within each list child when that list child is chosen? Currently it only shows data.
The reason is being, I don't want to download the images and store within the assets folder which will increase the size of the application, that's why use url to show only when that list child is chosen.
Is it possible? Or I could only do so by downloading the image beforehand and storing under assets?
Yes it is possible. If you want to implement this then you should grab a lazy loading library. For that you may use aquery just google it, its a nice library to provide the required mechanism.
Also Expandable istview is nothing but a listview so whatever you want to do inside a listviewcan be done within ExpandableListView as well.
What is the best practice for loading images from the Web into a ListView?
Do I have to load them first into SQLite database or should I load them directly into a ListView?
And also after clicking an item in the ListView I have to show the same image in another activity. Is it the right way to pass this image to another activity or it is better to load it from Web / SQLite once again?
Look here Lazy loading of images
Loading them directly into the listview will make scrolling in it slow, as it will reload them everytime they get visible.
do that Google recommended http://developer.android.com/training/displaying-bitmaps/index.html
I am using a GridView having image as child items.
The getView functions loads a default image from the application "Loading.gif" for all the child items.
In another thread I load all the images to some Bitmap type into the adapter.
Is it wise enough to call adapter.notifyDataSetChanged() after each image is loaded ?
Or is there and alternative way to directly update the image ?
Checkout the technique used in ListView , where default image used in listview items. And a thread load images for list items and update the new images without adapter.notifyDataSetChanged() called.
http://iamvijayakumar.blogspot.com/2011/06/android-lazy-image-loader-example.html
If you want more efficient way to do this then check this out.
http://developer.android.com/resources/samples/XmlAdapters/src/com/example/android/xmladapters/ImageDownloader.html