开发者

How to organize functions/methods in android app?

In my application, when user开发者_运维技巧 presses Sync button (calls function onSynchronize()), I need to do the following activities:

  1. form url for data synchronization based on user's preferences
  2. download url
  3. parse data received
  4. for each item found in data download picture (another url)
  5. update ListView with data downloaded and parsed

What is the best approach to split this activity between classes? Since steps 2-4 should be done in background (ASyncTask), and the same steps 1-4 will be used in the service (for automatic synchronization).

Should I put step 5 in onPostExecute of according ASyncTask? Or, should I put there steps 3-5? What is the most logical and clear approach?


First, you need an Adapter class for your ListView. Also you'll need a parser class(you can implement SAX or DOM if response is XML). Take a look at Lazy load of images in ListView to understand image downloading into ListView. Your parser class can return an array of custom objects and then you'll supply it to listview via your custom adapter class.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜