Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ViewPager carousel using PageContainer not working with FragmentPagerAdapter

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 ?

like image 892
magiccyril Avatar asked Jan 22 '13 09:01

magiccyril


People also ask

Can I use ViewPager with views not with fragments?

yes...you can use View instead of Fragment in viewpager.

Is ViewPager deprecated?

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.

What is the difference between PagerAdapter and FragmentPagerAdapter?

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 .

Should I use ViewPager or ViewPager2?

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 .


1 Answers

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.

like image 190
magiccyril Avatar answered Jan 01 '23 09:01

magiccyril