Original address
Content of this article
- Environment
- Demo Lazylist get pictures from the network and cache them
- Resources
This article is a demo on Github that gets a thumbnail of the singer's album over the Web and appears in the ListView control. The demo has the ability to cache thumbnails to the phone external memory, so it's called "Lazy" so it doesn't have to be fetched over the network every time.
The demo is just to get the thumbnail, but in another article, the author makes a relatively complete presentation (including information such as song name, artist name, duration, thumbnail, etc.), based on this lazylist, as shown in Figure 3.
Environment
- Windows R2 64-bit
- Eclipse ADT v22.6.2,android 4.4.3
- Samsung SM-G3508
Demo Lazylist get pictures from the network and cache them
The demo on GitHub has only one Java package, but I've re-divided it to make it easier to understand the author's ideas. Download here.
Figure 1 Project Structure
- The Com.fedorvlasov.lazylist.activity package is the main program.
- The Com.fedorvlasov.lazylist.cache package, which is responsible for caching, includes caching in external memory and memory.
- Com.fedorvlasov.lazylist.utils package, responsible for flow operation.
- The Com.fedorvlasov.lazylist.view package, which is responsible for getting the album's thumbnail from the web, and displaying it in the ListView while caching the thumbnail image. If the thumbnail is cached, the ListView gets and displays from the cache, otherwise it gets from the network.
Figure 2 Left: Main program, get thumbnail from network; Right: Click "Clear Cache" to clear cache reload
2, shown on the left, is the main program, which obtains thumbnails from the network and displays them. When the "Clear Cache" button is clicked, the program clears the cache, reloads and displays thumbnails, 2 to the right, showing the singer thumbnail, and what is not displayed, is not displayed, is getting from the network ~
Figure 3 Network Get music list
This is another relatively complete demo, click here to download, this demo is done on the basis of the lazylist, but there are bugs, the program is not stable, the program is not able to display the list every time, even if it appears, the thumbnail is not displayed, not yet understand what is going on, one of the bugs is because the version is lower, and Android 4.0 or more version does not allow access to the network in the main thread, you can try, if you understand, tell me ~
Resources
- Https://github.com/thest1/LazyList
- http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/
- http://blog.csdn.net/wangjinyu501/article/details/8219317
The relationship of these three links is that the second link to the demo is done based on the first link, and the third link translates the second connection.
Download Demo
Download Demo