So I've got this ListView and its adapter. It's using lazy loading of images with a transition effect from previous image to new.
It works great, but I have a problem and it's that my only reason to use a lazy load is to make scroll smooth. If I need to resort the listview I don't want images to lazy load as the transition is completely unnecessary.
I really don't know how to know inside the adapter whether the user is scrolling or the listview has been resorted. Any help is welcome, I found similar questions but none addressed this issue.
The concept of LazyLoading is that it loads the images for the first transition only and the images are cached. If the user again scrolls or if the ListView restores, it never downloads it again, images are taken from the local cache present on the device.
There are many Libraries that provide this feature :
Lazy List
Universal Loader
Volley
Picasso
Tutorial
Related
I am creating a Xamarin.Android application using MvvmCross framework.
I am currently using RecyclerViews to show a list of data and images, but once the item is out of the frame and loaded again it also loads the images.
I don't want that to happen, I want the images to be cached once loaded.
If anyone has any idea about how can I acheive that? I will thankful.
I have a Custom Adapter for the ListView. The Layout has three images, some text. When loading the Listview, it takes a while, because of the images. Its something like Posts.
Same app in iOS is loading very fast, I think that UITableView works different than Listview.
Is there a way, in place to load all posts, only load for example 3 posts and when the user scrolls the Listview down, load the next 3, scroll down, load the next 3 and so on. This could give a better performance.
Normally, android listview work that way. Let's say there are 5 views that user can reach at the moment. ListView creates 9 views and when user scrolls it loads the bottom ones. You can think it this way. Your main problem is how are you loading your images and create the custom view. There is a common pattern for custom adapters which handles the fast recycling views(ViewHolder pattern). You should checkout the link for ViewHolder pattern. https://www.javacodegeeks.com/2013/09/android-viewholder-pattern-example.html
It probably loads slow because the images should be resized every time, if you could save thumbnails it would go much faster.
Have you tried to use Recycler View instead? As long as I know using the Recycler View is the best practice nowadays. You can find a very good tutorial here:
http://www.vogella.com/tutorials/AndroidRecyclerView/article.html
You use the Recycler View almost the same way you do with List View: adapter, viewHolder, etc. It's good to mention though that you need to pay special attention to the use of the LayoutManager since the Recycler View it itself doesn't "know how to draw" the stuff on the screen.
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.
I saw a lot of implementations of smooth downloading images from web and showing them in listView with cache. Now I have the following situation: I'm storing images to SDCard and sometimes my listView shows them instead of images from web resource. In this case navigation in listView is not smooth. Do you know any good implementation of listView with image from sdCard?
Multithreading is the answer!
http://android-developers.blogspot.com/2010/07/multithreading-for-performance.html
Just ignore the the sections for downloading, but idea is the same!
Then check this code :
Lazy load of images in ListView