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:
- form url for data synchronization based on user's preferences
- download url
- parse data received
- for each item found in data download picture (another url)
- 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.
精彩评论