Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cache listview data in android?

I have a Listview that contains 100 rows. This is the first time I load all the data from a Webservice. I want to cache that data so that if I open that page I should get it from cache not from the Webservice. How can I do this?

like image 872
Sandy Avatar asked Apr 08 '11 13:04

Sandy


2 Answers

If your data is simple enough, just store them in an array and use something like ArrayAdapter to bind the data to the list view.

If your data is more complex, then an SQLite table is probably preferable. In this case use something like SimpleCursorAdapter.

like image 62
Rollin_s Avatar answered Sep 18 '22 12:09

Rollin_s


You can store the data as a JSON file in your application's internal storage space. I find that this is a much easier approach, as you can easily map the JSON to Model classes using a library like Gson. You would typically follow this approach if the data you have will not be "updated" like you might do in a traditional database(although you are still able to update your JSON data, just differently).

like image 39
james Avatar answered Sep 22 '22 12:09

james