如何实现在Android的ListView控件缓存 [英] How to implement ListView caching in Android

查看:148
本文介绍了如何实现在Android的ListView控件缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ListView其中包含了大量的数据。
在第一时间,我加载从Webservice的所有数据。

I have a ListView which contains a large set of data.
At the first time, I load all the data from a Webservice.

现在我想缓存的数据,这样,如果我再次打开该网页,我可以从缓存中读取再次查询Web服务的数据来代替。

Now I want to cache that data so that, if I'm to open that page again, I can fetch the data from the cache instead of querying the webservice again.

我该怎么办呢?

推荐答案

我假设你存储从的WebService 在一个序列化对象检索的数据(如在规定您编辑它之前你的问题。)

I assume you're storing the data retrieved from WebService in a serializable object (as you stated in your question before you edited it.)

您可以存储序列化的对象到一个文件以后加载它们:

You can store serializable objects into a file and load them later:

存储:

FileOutputStream fileOutputStream = yourContext.openFileOutput(fileName, Context.MODE_PRIVATE);
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
objectOutputStream.writeObject(yourObject);
objectOutputStream.close();

负载:

FileInputStream fileInputStream = yourContext.openFileInput(fileName);
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
Object yourObject = (Object)objectInputStream.readObject();
objectInputStream.close();

这篇关于如何实现在Android的ListView控件缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆