我是靠谱客的博主 多情电脑,这篇文章主要介绍android清空 list,list - How to clear cache Android - Stack Overflow,现在分享给大家,希望可以做个参考。

I need to find a way how to clear the data which my application stores in cache.Basically I am using Fedor's ( Lazy load of images in ListView ) lazy list implementation and I want to clear the cache automatically when I have for example 100 images loaded.Any ideas how to do that?

EDIT:

Code :

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

list=(ListView)findViewById(R.id.list);

adapter=new LazyAdapter(this, mStrings);

list.setAdapter(adapter);

deleteCache(this);

adapter.notifyDataSetChanged();

}

public static void deleteCache(Context context) {

try {

File dir = context.getCacheDir();

if (dir != null && dir.isDirectory()) {

deleteDir(dir);

}

} catch (Exception e) {}

}

public static boolean deleteDir(File dir) {

if (dir != null && dir.isDirectory()) {

String[] children = dir.list();

for (int i = 0; i < children.length; i++) {

boolean success = deleteDir(new File(dir, children[i]));

if (!success) {

return false;

}

}

}

return dir.delete();

}

最后

以上就是多情电脑最近收集整理的关于android清空 list,list - How to clear cache Android - Stack Overflow的全部内容,更多相关android清空内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(124)

评论列表共有 0 条评论

立即
投稿
返回
顶部