ViewPager + 片段中的适配器 =>延迟刷卡 [英] ViewPager + Adapter in Fragment => laggy swiping

查看:27
本文介绍了ViewPager + 片段中的适配器 =>延迟刷卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有一些片段的 ViewPager.每个片段在带有 ArrayAdapterSlidingDrawer(=在滑动前不可见)中都有一个 ListView.

I have a ViewPager with some fragments. Each fragment has a ListView in a SlidingDrawer (=invisible before swiping) with an ArrayAdapter.

适配器设置在 onCreateView() 上,这会减慢滑动速度,因为每次滑动时必须加载 30 个列表项,因为正在创建新片段.

Adapter is set on onCreateView(), that slows down swiping, because 30 list items have to load each time I swipe, because new fragments are being created.

我的问题是,当 ViewPager 空闲时,是否可以在刷卡后设置适配器?或者,还有更好的方法?当 SlidingDrawer 展开时,列表需要已经加载.

My Question is, whether it is possible to set the adapter after swiping when it ViewPager is idle? Or is there a better way? The List needs to be already loaded when the SlidingDrawer is expanded.

推荐答案

我的问题是,是否可以在刷卡后设置适配器Pager 什么时候空闲?

My Question is, wether it is possible to set the Adapter after swiping when it Pager is idle?

OnPageChangeListener 您可以在 ViewPager 上设置以监控滑动手势.然后,您可以使用 onPageSelected()(或 onPageScrollStateChanged() 来监视当前状态)方法在选择新页面时获得通知并从该方法开始数据加载.

There is the OnPageChangeListener that you could set on the ViewPager to monitor the swipe gestures. You could then use the onPageSelected()(or the onPageScrollStateChanged() to monitor the current state) method to get notified when a new page has been selected and start from that method the loading of data.

另外,请确保 ListView 对延迟负责,而不是代码的其他部分.

Also, make sure the ListView are responsible for the lag and not some other part of your code.

这篇关于ViewPager + 片段中的适配器 =>延迟刷卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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