Caching images and displaying

后端 未结 5 973
臣服心动
臣服心动 2020-11-22 15:37

Hello Am facing a particular problem in which I need to download images and display them onto a ListView corresponding to their particular TextView\'s

5条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 16:16

    Do you want something easy to use? With take care of caching files, deleting the cache, release when the memory is at border line?

    Try LazyList, check it out:

    https://github.com/nicolasjafelle/LazyList

    As it is explained, you only need to create the Singleton in your Application class or any other Activity or Fragment:

    //To use the default external folder, this folder will be deleted when the app no longe exists.
    ImageLoader.getInstance().init(getApplicationContext());
    //Or to use another folder, use...
    //ImageLoader.getInstance().init(getApplicationContext(), "MyExternalFolder");
    

    Then in your view that has the ImageView to display de Image you need to implement ImageProcessingCallback interface:

    public class MyItemView extends LinearLayout implements ImageProcessingCallback {
    ...
    //Do what you need in methods onImagePreProcessing() and onImageProcessing(Bitmap     bitmap)
    ...
    ImageLoader.getInstance().displayImage(data[position], myView);
    

    Finally you need to add this permission in your androidManifest.xml

    
    
    

    And that's it. Then you have methods to clear the cache for ram cache or disk cache or both.

提交回复
热议问题