我在我的测试应用程序中使用了fedor的懒加载列表实现,其中我可以通过单击一个按钮来清除缓存。如何获取ListView中已加载图像的缓存大小并以编程方式清除缓存?
以下是保存缓存图像的代码:
以下是保存缓存图像的代码:
public ImageLoader(Context context){
//Make the background thead low priority. This way it will not affect the UI performance.
photoLoaderThread.setPriority(Thread.NORM_PRIORITY-1);
mAssetManager = context.getAssets();
//Find the dir to save cached images
if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
cacheDir = new File(android.os.Environment.getExternalStorageDirectory(),"LazyList");
else
cacheDir = context.getCacheDir();
if(!cacheDir.exists())
cacheDir.mkdirs();
}
编辑:
所以基本上我在clearCache()方法中添加了这段代码,但是当我滚动时,我仍然看不到图片重新开始加载。
public void clearCache() {
//clear memory cache
long size=0;
cache.clear();
//clear SD cache
File[] files = cacheDir.listFiles();
for (File f:files) {
size = size+f.length();
if(size >= 200)
f.delete();
}
}
if(size>=200)
的情况下执行代码f.delete()
? - ilango j