使用远程数据填充 ListFragment
我有一个 ListFragment,当前填充有静态数据,在编译时修复。我实际上希望从网络上截取列表的数据。
我计划使用 jsoup 进行检索和解析等。但是将 jsoup 链接到 ListFragment 的最佳方法是什么?
我应该使用 AsyncTaskLoader 等加载器吗?我不确定,因为 API 文档说加载器应该“监视数据源并在内容更改时提供新结果”,但检索 ListFragment 的数据将是一次性操作:不需要来监控源头。
如有任何建议,我们将不胜感激。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了同样的问题,为了解决它,我必须扩展 AsyncTaskLoader 并且工作正常。
上
public List loadInBackground() 我正在下载数据,仅此而已。
我建议检查支持 v4 示例android/support/v4/samples/Support4Demos/src/com/example/android/supportv4/app/LoaderCustomSupport.java
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
是的,你应该使用 AsyncTaskLoader。使用doInBackground()方法进行解析,使用onPostExecute()方法从jsoup数据中检索。
由于您使用的是 ListFragment,如果您想将信息从 AsyncTaskLoader 传递到 ListFragment,您可能会发现以下文章很有用。技巧是使用一个接口从 AsyncTaskLoader 回调到 ListFragment。
使用接口从Task回调到Fragment
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