【发布时间】:2011-08-12 06:48:13
【问题描述】:
我在我的测试应用程序中使用了 fedor 的延迟加载列表实现,我可以通过单击一个按钮来清除缓存。如何获取列表视图中加载图像的缓存大小并以编程方式清除缓存?
这里是保存缓存图像的代码:
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();
}
}
【问题讨论】: