Search code examples
androidlistviewcachingandroid-custom-view

Save a ListView in Cache?


I want to save a ListView on the cache, but I don't know how to do. The List is read from SQL and arranged alphabetically. It has separators, so it has to read all entries and classify them by letter for add the spacer to the right place. I think is faster to save the list in the cache than build it everytime. It's right? How can I save a View in cache?


Solution

  • I think is faster to save the list in the cache than build it everytime. It's right?

    not necessarily true, assuming saving the list = saving the entire View and it's drawing cache. anyway I don't think there's a trivial way doing such a thing.

    but the good news are that you really don't need to do that!

    if you're list does not load's fast it's probably because you're doing lot's of operation's inside the getView() method, such as decoding Bitmaps, parsing heavy data, or something like that.

    if you want to do it in the right way - cache the images if you've got ones, then next time load them from the cache and do the decoding in a separate thread (by using AsyncTesk or one of other's API components for such purposes). if you are heaving some heavy calculations or parsing you are doing - cache the result's in the database also, and load them next time (save the data in alphabetical arranged in the database for instance)

    there is really no reason you feel any slowness in the user experience using such approach. views not suppose to be "saved" in the way you described, and I really believe there is no reason to do so because Android's mechaniszem for "loading" views working just great if using it properly

    hope it helped you, and good luck.