开发者

List View Design Pattern

开发者 https://www.devze.com 2023-01-14 03:03 出处:网络
I am having a List View, all the list items(Text) need be to updated from a web service. My application can query the web service to fetch all the list开发者_StackOverflow中文版 items at one go or can

I am having a List View, all the list items(Text) need be to updated from a web service. My application can query the web service to fetch all the list开发者_StackOverflow中文版 items at one go or can query to fetch one list item at a time. I having following queries 1)If i query the web service to fetch all the list items at once, it takes around 15 secs to download and display it in List. User might think the app is not responding. 2) If i query the web service for each list item, when the user scroll up or down multiple queries are sent. So i am downloading items which the user might not probably see. if the list is scrolled up.

Please suggest a good design pattern for such a scenario.


What you could do is to have the following

  • A background Android service which downloads fresh items from your webservice in given time intervals
  • A sqlite database and according ContentProvider which stores/fetches the items from the DB
  • A list activity which retrieves a cursor on the items from the registered ContentProvider you wrote

Basically the background service will store the items in the local sqlite db through the ContentProvider you write. The activity will then retrieve a cursor to the items, again through the ContentProvider.

This gives you the benefits that

  • it will be fast, working with cursors and standard mechanisms
  • users will still see the items also if they temporaneously loose connectivity
  • your list will automatically refresh the items, being registered as Observer on the ContentProvider
0

精彩评论

暂无评论...
验证码 换一张
取 消