FragmentStatePagerAdapter first call to getItem wrong with sdk 22-->23 upgrade

*爱你&永不变心* 提交于 2019-12-06 10:43:20
DmitryO.

The idea that I posted as a comment resolved the problem, here is the same answer with a few more details...

Short version: in adapters derived from FragmentStatePagerAdapter, try to use FragmentManager instead of SupportFragmentManager. Unless you're 100% sure you need the SupportFragmentManager.

Explanation:

code in the question looks pretty good. The only place where adapter can 'confuse' fragments is the method instantiateItem(ViewGroup container, int position). This method uses a FragmentManager passed as an argument of constructor. So we can blame that suspicious SupportFragmentManager.

Daniel Nugent

To add to the answer from DmitryO, you should use FragmentManager if you are using android.app.Fragment, and use SupportFragmentManager if you are using android.support.v4.app.Fragment, simple as that.

Both can be used in conjunction with the Support Library, i.e. you can put either type of Fragment in an AppCompatActivity. Also note that if you want to use android.app.Fragment native Fragments with a FragmentPagerAdapter or FragmentStatePagerAdapter, you need to use the v13 support library versions of the adapter, i.e. android.support.v13.app.FragmentStatePagerAdapter.

Note, this was originally posted as a comment, but I didn't want this info to get lost.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!