ViewPager + 片段中的适配器 =>延迟刷卡
我有一个带有一些片段的 ViewPager
.每个片段在带有 ArrayAdapter
的 SlidingDrawer
(=在滑动前不可见)中都有一个 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.
相关文章