无尽适配器ViewPager [英] Endless adapter for ViewPager

查看:186
本文介绍了无尽适配器ViewPager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直使用 CWAC的EndlessAdapter 实现对列表视图无限滚动。

我想实现相当于一个ViewPager。不幸的是,PageAdapter和ListAdapter不共享相同的公共基类

什么是去了解这一点的最好方法是什么?难道一个图书馆存在已经处理呢?

解决方案
  

什么是去了解这一点的最好方法是什么?

添加没完没了的逻辑来自己实施 PagerAdapter 的。或者,如果你愿意的话,尝试创建一个装饰 PagerAdapter ,的方式, EndlessAdapter 装修普通的适配器

后者很可能会非常棘手,因为 PagerAdapter 是专为网页是意见或片段,和片段处理的类中如 FragmentPagerAdapter 是一个有点吓人。

  

难道一个图书馆存在已经处理呢?

没有,我是知道的。

主要,这是因为使用情况似乎并不引人注目。随着的ListView ,用户可以一扔列表,通过数十个或数百个行的非常迅速滚动。因此,用我们到了年底作为触发加载更多的数据似乎是合理的。随着 ViewPager ,但是,它通常需要更长的时间来进行到底,特别是如果你不使用 PagerTabStrip 或等同。因此,等待,直到用户得到一路年底开始加载额外的数据似乎将是恼人的用户 - 你有这么长的时间去获取更多的数据,但没有使用它。

这是另一种,因此,这是为你注册 ViewPager.OnPageChangeListener ViewPager 。当 onPageSelected(),你认为自己是接近了尾声,揭开序幕的的AsyncTask (或其他)去收集更多的数据。美中不足的则是,你将需要更新的适配器上使用的 PagerAdapter 和呼叫数据 notifyDataSetChanged()一旦数据已被更新。

I've been using CWAC's EndlessAdapter to achieve infinite scrolling on ListViews.

I'd like to accomplish the equivalent for a ViewPager. Unfortunately, PageAdapter and ListAdapter do not share the same common base class.

What's the best way to go about this? Does a library exist that already handles this?

解决方案

What's the best way to go about this?

Add "endless" logic to your own implementation of PagerAdapter. Or, if you wish, try creating a decorating PagerAdapter, the way that EndlessAdapter decorates a regular Adapter.

The latter is likely to be tricky, given that PagerAdapter is designed for pages to be views or fragments, and the fragment handling inside of classes like FragmentPagerAdapter is a bit scary.

Does a library exist that already handles this?

None that I am aware of.

Mainly, that is because the use case doesn't seem as compelling. With a ListView, the user can fling the list, scrolling through dozens or hundreds of rows very quickly. Hence, using "we got to the end" as the trigger to load more data seems reasonable. With a ViewPager, though, it typically takes a lot longer to get to the end, particularly if you are not using PagerTabStrip or the equivalent. Hence, waiting until the user gets all the way to the end to begin loading additional data seems like it would be annoying to the user -- you had all this time to go retrieve more data, but didn't use it.

An alternative, therefore, is for you to register a ViewPager.OnPageChangeListener with your ViewPager. When onPageSelected(), and you consider yourself to be close to the end, kick off an AsyncTask (or whatever) to go gather more data. The catch then is that you will need to update the data used by the PagerAdapter and call notifyDataSetChanged() on that adapter once the data has been updated.

这篇关于无尽适配器ViewPager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆