Вопрос

I have a ListFragment, currently populated with static data, fixed at compile time. I actually want the data for the list to be screenscraped from the web.

I plan to use jsoup to do the retrieval and parsing etc. But what's the best way to link jsoup to the ListFragment?

Should I be using a Loader such as AsyncTaskLoader? I wasn't sure because the API docs say that loaders should "monitor the source of their data and deliver new results when the contents change", but retrieving the data for my ListFragment will be a one-time operation: there will be no need to monitor the source.

Any advice would be gratefully received.

Это было полезно?

Решение

I had the same problem, to solve it i had to extend AsyncTaskLoader and works OK. On the public List loadInBackground() i'm downloading the data and that's all.

I recommend's that check the support v4 samplesandroid/support/v4/samples/Support4Demos/src/com/example/android/supportv4/app/LoaderCustomSupport.java

Другие советы

Yes you should use AsyncTaskLoader. Use the doInBackground() method to do the parsing, and onPostExecute() method to retrieve the from jsoup data.

Since you're using ListFragment, you might find the following post useful, if you want to pass information from AsyncTaskLoader to your ListFragment. The trick is to use an interface to callback from AsyncTaskLoader to your ListFragment.

Use Interface to callback from Task to Fragment

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top