简体   繁体   English

Android:如何生成多个加载程序

[英]Android: How to Spawn Several Loaders

I am working on an Android app. 我正在开发一个Android应用程序。 I am using a Custom extension of AsyncTaskLoader to retrieve a JSON Array of elements from a website. 我正在使用AsyncTaskLoader的Custom扩展从网站检索元素的JSON数组。 Data are correctly retrieved and parsed. 数据已正确检索和解析。

Now for each object of such array I need to spawn a Loader which is aimedt at retrieving its detailed description (another URL). 现在,对于此类数组的每个对象,我需要生成一个Loader,该Loader旨在检索其详细说明(另一个URL)。 I have implemented such Loader but I don't know where it should be spawned. 我已经实现了这样的Loader,但是我不知道应该在哪里生成它。

Basically my confusion is due to the fact that the onCreateLoader method implemented by the Fragment receiving the Loaders' results (LoaderCallBacks) is supposed to return only one Loader. 基本上,我的困惑是由于这样一个事实,即由接收到加载程序结果的Fragment(LoaderCallBacks)实现的onCreateLoader方法应该只返回一个加载程序。

Basically my confusion is due to the fact that the onCreateLoader method implemented by the Fragment receiving the Loaders' results (LoaderCallBacks) is supposed to return only one Loader. 基本上,我的困惑是由于这样一个事实,即由接收到加载程序结果的Fragment(LoaderCallBacks)实现的onCreateLoader方法应该只返回一个加载程序。

it is almost true. 这几乎是真的。 The onCreateLoader 's signature is onCreateLoader的签名是

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) 

you can use the first argument to spawn different loader. 您可以使用第一个参数生成其他加载程序。 Of course, you have to use initLoader / restartLoader , a number of times equal to the number of loader to spawn, each with a different id 当然,您必须使用initLoader / restartLoader ,其次数等于要生成的加载器的次数,每次都有不同的id

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM