0

I got the following code, that is run everytime I want to change the contents on screen:

        if (Globals.PagerAdapter.Count == 0) {
            SetContentView(Resource.Layout.Loading);
        } else {
            Pager = new ViewPager(this);
            Pager.Id = PagerID++; // Dummy id, not setting one will cause crash
            Pager.Adapter = Globals.PagerAdapter;

            if (currentFrame >= 0) {
                Pager.SetCurrentItem(currentFrame, false);
            }

            SetContentView(Pager);
        }

The Globals.PagerAdapter, and the backing data, is of course changed before this code is run. The problem I have, is that when I call this method, the viewpager being used is the same, event though I explicetly create a new one. All that happens really, is that it moves to the first fragment of the viewpager.

What am I missing here?

Robin Heggelund Hansen
  • 4,906
  • 6
  • 37
  • 54
  • Maybe it helps http://stackoverflow.com/questions/10849552/android-viewpager-cant-update-dynamically – User Mar 03 '13 at 16:12
  • Ahh no, I've allready edited my FragmentStatePagerAdapter to return POSITION_NONE when appropriate, so it's not the same issue. Besides, now I'm creating a whole new ViewPager, not editing the contents of the one I have. – Robin Heggelund Hansen Mar 03 '13 at 16:17
  • How do you know that the viewpager is the same? Maybe you're not updating the data, and you just get a new viewpager with the same data... – User Mar 03 '13 at 16:46
  • Cause I create a new ViewPager, and before calling this function I change the contents of the PagerAdapter... – Robin Heggelund Hansen Mar 03 '13 at 19:07
  • 1
    Well, you should post more code. And anyways, your method seems strange - you should be using the same viewpager instance, update the adapter, and see that the viewpager gets updated. Asigning ids in this way is also insecure. + Having an adapter as a static variable of "Globals" looks like very bad practice. + Count as static variable of the adapter... and what is Resource.Layout.? Shouldn't it be R.layout.? (at least if you're using the standard SDK - don't know what else is around) – User Mar 03 '13 at 19:22
  • I'm using Xamarin.Android, which is why some of this code seems wierd. I keep the adapter in "Globals" (Application class) for persistance, as things didn't work well when rotating. But using the same adapter seemed to work. I'm still pussled though, why shouldn't creating a new viewpager work? – Robin Heggelund Hansen Mar 03 '13 at 22:17

0 Answers0