5

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 ?

magiccyril
  • 657
  • 1
  • 6
  • 14

2 Answers2

9

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.

magiccyril
  • 657
  • 1
  • 6
  • 14
  • I was getting exactly the same error with my code - I was creating my viewpager on the fly and putting it into a container view i already had in xml, but by creating the view in xml and giving it an id the error went away! Must be a bug with android not assigning an id properly... – AndroidNoob Jan 22 '13 at 11:21
4

The documentation explicitly says so:

When using FragmentPagerAdapter the host ViewPager must have a valid ID set.

I'm glad I found your answer because it was giving me a headache for quite some time as well. Soon as I saw your answer I remember skimming it and feeling like an idiot.

MadTom
  • 95
  • 2
  • 8
  • Helps a lot! Especially when adding a viewpager programatically, as you tend to forget those little things heaha – phazedlite Sep 02 '14 at 07:03