模式的使用动态加载程序来加载未经ListFragments一个ViewPager ListView的页面?加载、模式、页面、程序

2023-09-06 15:45:07 作者:杀尽所有负心狗ァ

如果我有一个 ViewPager 一定数量的网页,这将是使用加载的每一页数据的最佳方式装载机框架?每个页面都包含有自己的适配器实例一个ListView。

If I have a ViewPager with a certain number of pages, what would be the best way of loading the data for each page using the Loader framework? Each page contains a ListView with its own adapter instance.

使用的每一页单独装载机;或使用,检查未载入页面的单个加载器并加载它们

问题是,这是可能的,用户可能希望尽快通过一堆网页刷卡,因此它应该是容易取消,则不需要出于性能方面的加载页面。

The thing is, it's possible the user may want to quickly swipe through a bunch of pages and thus it should be easy to "cancel" loading pages that aren't needed for performance reasons.

在另一方面,它好像有可能是与具有很多装载机的开销

On the other hand it seems like there might be an overhead with having a lot of loaders.

编辑:我的装载机 5事实上需要有动态ID重新present它们加载内容。我可能会去使用对装载机ID的面具,那么一旦加载完成后调用 destroyLoader()

My Loaders actually need to have dynamic IDs to represent the content they are loading. I'm probably going to go with using a mask on the loader ID, and then once the loader is done call destroyLoader().

推荐答案

我会用一个单独的装载机每个 ListFragment 。事情会变得混乱很快,如果你试图管理的片段装载机从父小号活动(特别是如果这些片段正在举行由 ViewPager )。 片段应该s到设计重用,不应该依靠才能正常工作的特定活动。事实上,每个活动,每个片段获得自己的 LoaderManager 实例进一步证明,Android团队并不希望开发者有自己的活动 S代表其附加的片段秒。

I would use a separate Loader for each ListFragment. Things will get messy very quickly if you try to manage the fragments' Loaders from the parent Activity (especially if those fragments are being held by a ViewPager). Fragments are supposed to be designed for reuse and should not rely on a specific Activity in order to function properly. The fact that each Activity and each Fragment get their own LoaderManager instance is further evidence that the Android team didn't want developers to have their Activitys loading data for its attached Fragments.

我不认为会有尽可能多的开销,你可能希望那里是... 装载机取值应保留在整个组件的生命周期和重新它们的数据-query只有当基本内容已经改变。这可能是使用一个好主意,一个 FragmentStatePagerAdapter 了。

I don't think there will be as much overhead as you are probably expecting there to be... Loaders should retain their data across the component's lifecycle and re-query only when the underlying content has changed. It might be a good idea to use a FragmentStatePagerAdapter too.