I'm using https://gist.github.com/8cbe094bb7a783e37ad1 in order to display multiple page of a ViewPager at once. It works great with a simple PageAdapter, but I need to display a large amount of Bitmaps. So I read http://developer.android.com/training/displaying-bitmaps/index.html and it says :
You can implement this pattern using a ViewPager component backed by a PagerAdapter. However, a more suitable backing adapter is the subclass FragmentStatePagerAdapter which automatically destroys and saves state of the Fragments in the ViewPager as they disappear off-screen, keeping memory usage down.
I tried to create a new FragmentStatePagerAdapter but it doesn't work :
E/AndroidRuntime(25400): android.content.res.Resources$NotFoundException: Unable to find resource ID #0xffffffff
I really don't understand what's the error, because I'm not using any particular resources except layouts.
Does anyone have an idea how to resolve this ?
yes...you can use View instead of Fragment in viewpager.
This method may be called by the ViewPager to obtain a title string to describe the specified page. This method is deprecated. This method should be called by the application if the data backing this adapter has changed and associated views should update.
The difference is that you can use Fragments inside a FragmentPageAdapter . If you want to have fragments that are going to be used in other parts of your code this is your Adapter. Otherwise if you only want to have code that isn't going to be reused, you can use PagerAdapter .
ViewPager2 is an improved version of the ViewPager library that offers enhanced functionality and addresses common difficulties with using ViewPager . If your app already uses ViewPager , read this page to learn more about migrating to ViewPager2 .
I just discover that it works when I add an android:id to the ViewPager inside the PageContainer. So, just with an id it seems to work, but I don't understand why.
If someone have an idea, I'll be glad to understand.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With