My application loads a ListView populated from a remote XML file. Each row following the first needs to be fetched in multiple http requests.
For example, the XML file looks something like:
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <item>available content</item> <item>unavailable</item> <item>unavailable</item> <item>unavailable</item> <item>unavailable</item>
From this, I create an ArrayList that maps to an adapter.
In my GetView(), I check for the String "unavailable" in the ArrayList, and if found, launch an AsyncTask that I pass the corresponding row, position, and URL to (each item from the XML file also has a url value). Then in onPostExecute, I use row.findViewById() and setText() to update the ListView with the new content fetched by the unavailable item's URL
This all works, but only on rows that are visible on the screen. e.g. if there are 10 total rows, and I see 5 on the screen at a time, when I scroll down to the bottom, the same values for the first five are displa开发者_如何转开发yed for a second before updating to the correct values. Then the same thing happens when I scroll back up. So, is there something I can use that will act like getView and pass each row to an AsyncTask, but that is called only once, for the whole ListView?
Eh, not really. I'd say you're doing it right: do it in getView() but have the AsyncTask actually update the item in the ArrayList so it doesn't fire again. If you're backed with an ArrayList you CAN just change the value at that position and then do <adapter>.notifyDataSetChanged();
to update things.
精彩评论