• <tfoot id='1PeXX'></tfoot>
  • <small id='1PeXX'></small><noframes id='1PeXX'>

      <bdo id='1PeXX'></bdo><ul id='1PeXX'></ul>

      <i id='1PeXX'><tr id='1PeXX'><dt id='1PeXX'><q id='1PeXX'><span id='1PeXX'><b id='1PeXX'><form id='1PeXX'><ins id='1PeXX'></ins><ul id='1PeXX'></ul><sub id='1PeXX'></sub></form><legend id='1PeXX'></legend><bdo id='1PeXX'><pre id='1PeXX'><center id='1PeXX'></center></pre></bdo></b><th id='1PeXX'></th></span></q></dt></tr></i><div id='1PeXX'><tfoot id='1PeXX'></tfoot><dl id='1PeXX'><fieldset id='1PeXX'></fieldset></dl></div>
        <legend id='1PeXX'><style id='1PeXX'><dir id='1PeXX'><q id='1PeXX'></q></dir></style></legend>
      1. ViewPager 的无尽适配器

        时间:2023-10-04
        1. <tfoot id='5UKdM'></tfoot>
          <legend id='5UKdM'><style id='5UKdM'><dir id='5UKdM'><q id='5UKdM'></q></dir></style></legend>

            <tbody id='5UKdM'></tbody>

              • <bdo id='5UKdM'></bdo><ul id='5UKdM'></ul>
                • <small id='5UKdM'></small><noframes id='5UKdM'>

                • <i id='5UKdM'><tr id='5UKdM'><dt id='5UKdM'><q id='5UKdM'><span id='5UKdM'><b id='5UKdM'><form id='5UKdM'><ins id='5UKdM'></ins><ul id='5UKdM'></ul><sub id='5UKdM'></sub></form><legend id='5UKdM'></legend><bdo id='5UKdM'><pre id='5UKdM'><center id='5UKdM'></center></pre></bdo></b><th id='5UKdM'></th></span></q></dt></tr></i><div id='5UKdM'><tfoot id='5UKdM'></tfoot><dl id='5UKdM'><fieldset id='5UKdM'></fieldset></dl></div>
                  本文介绍了ViewPager 的无尽适配器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我一直在使用 CWAC 的 EndlessAdapter 来实现 ListView 的无限滚动.

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

                  我想完成 ViewPager 的等效操作.不幸的是,PageAdapter 和 ListAdapter 不共享同一个公共基类.

                  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?

                  将无尽"逻辑添加到您自己的 PagerAdapter 实现中.或者,如果您愿意,可以尝试创建一个装饰 PagerAdapter,就像 EndlessAdapter 装饰常规 Adapter 一样.

                  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.

                  后者可能比较棘手,因为 PagerAdapter 是为将页面设计为视图或片段的,并且像 FragmentPagerAdapter 这样的类内部的片段处理有点吓人.

                  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?

                  我不知道.

                  主要是因为用例似乎没有那么引人注目.使用 ListView,用户可以快速翻阅列表,快速滚动数十或数百行.因此,使用we got to end"作为加载更多数据的触发器似乎是合理的.但是,使用 ViewPager 时,通常需要更长的时间才能到达终点,尤其是在您不使用 PagerTabStrip 或同等功能的情况下.因此,等到用户一直到最后才开始加载额外的数据似乎会让用户感到厌烦——你一直有时间去检索更多的数据,但没有使用它.

                  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.

                  因此,您可以使用 ViewPager 注册一个 ViewPager.OnPageChangeListener.当 onPageSelected() 并且您认为自己接近尾声时,启动一个 AsyncTask(或其他)以收集更多数据.然后问题是,您需要更新 PagerAdapter 使用的数据,并在数据更新后在该适配器上调用 notifyDataSetChanged().

                  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 的无尽适配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Android ViewPager with ScrollViews with ViewPagers inside th 下一篇:带有标签和 Viewpager 的 Android 片段

                  相关文章

                    1. <tfoot id='j6dn0'></tfoot>

                      <legend id='j6dn0'><style id='j6dn0'><dir id='j6dn0'><q id='j6dn0'></q></dir></style></legend>
                        <bdo id='j6dn0'></bdo><ul id='j6dn0'></ul>

                      <small id='j6dn0'></small><noframes id='j6dn0'>

                      <i id='j6dn0'><tr id='j6dn0'><dt id='j6dn0'><q id='j6dn0'><span id='j6dn0'><b id='j6dn0'><form id='j6dn0'><ins id='j6dn0'></ins><ul id='j6dn0'></ul><sub id='j6dn0'></sub></form><legend id='j6dn0'></legend><bdo id='j6dn0'><pre id='j6dn0'><center id='j6dn0'></center></pre></bdo></b><th id='j6dn0'></th></span></q></dt></tr></i><div id='j6dn0'><tfoot id='j6dn0'></tfoot><dl id='j6dn0'><fieldset id='j6dn0'></fieldset></dl></div>