android.support.v4.app.FragmentPagerAdapter的getItem(INT位置)被调用两次? [英] android.support.v4.app.FragmentPagerAdapter getItem(int position) being called twice?

查看:423
本文介绍了android.support.v4.app.FragmentPagerAdapter的getItem(INT位置)被调用两次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含片段的视图寻呼机。当片段寻呼机适配器首先被实例化,为getItem(INT位置)方法必须实现被调用两次,这是在碎片造成麻烦,因为我基于位置获取数据。因此,例如,一个LOG打印表明它是第一位置0,则位置1

I have a view pager which contains a fragment. When the fragment pager adapter first gets instantiated, the getItem(int position) method that must be implemented gets called twice, which is causing trouble in the Fragment since I am getting data based on the position. So for example, a LOG print reveals that it is first position 0, then position 1.

任何想法,为什么发生这种情况?

Any ideas why this is happening?

我下面的例子在这里:<一href=\"http://wptrafficanalyzer.in/blog/implementing-horizontal-view-swiping-using-viewpager-and-fragmentpageradapter-in-android/\" rel=\"nofollow\">http://wptrafficanalyzer.in/blog/implementing-horizontal-view-swiping-using-viewpager-and-fragmentpageradapter-in-android/

I am following the example here: http://wptrafficanalyzer.in/blog/implementing-horizontal-view-swiping-using-viewpager-and-fragmentpageradapter-in-android/

推荐答案

的getItem(INT位置)被称为加载(连接)的片段,以它的位置在片段寻呼机。默认情况下,不仅在可见片段被加载,而且下一个和previous之一。因此,当您滚动到第二页,你会看到它会加载第三位。当你去到第3,这将卸下第一片段,并加载了第4位。当您返回到第2段,西港岛线就再次加载第一片段。等等。

the getItem(int position) is called for loading (attaching) the fragment to its position in the fragment pager. By default, not only the visible fragment is loaded, but also the next one and previous one. So when you scroll to the 2nd 'page', you will see it will load the 3rd. When you go to the 3rd, it will unload the 1st fragment, and load the 4th. When you go back to the 2nd fragment, it wil load the 1st fragment again. And so on.

这篇关于android.support.v4.app.FragmentPagerAdapter的getItem(INT位置)被调用两次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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