2

I am trying to construct an application where you can scroll through objects with a ViewPager. The ViewPager holds Fragments, support library due to SDK 9 restriction. The fragments are constructed from data in a bean-object.

When I leave the active view (with a transaction.replace) to another fragment (and returns) the page I'm on and 1-2 to the left and the right becomes blank- nothing from the xml is shown and the background of the ViewPager-xml-element is shown. When scrolling x pages the content returns to the pages (not all of them, you need to scroll around more for that). When I enter and leave a PreferenceActivity, I do not get this error.

What is causing this behaviour and how can I fix it?

My app looks like this:

1 FragmentActivity that has a FrameLayout. 2 fragments that replaces each other when called. Inside one of the fragments, browser, is some buttons and a ViewPager. The ViewPager has a (Fixed 1)FragmentStateChangeAdapter. If this is changed to FragmentChangeAdapter there is no difference.

The activity has a list of beans used in the ViewPager and a ListView in the other fragment, Search.

I've tried some suggestions without result:

ViewPager + FragmentStatePagerAdapter + orientation change

A bug in (and a fix for) the way FragmentStatePagerAdapter handles fragment restoration

I can supply code but this feels like a theory question, maybe in regard to saved states etc.

Community
  • 1
  • 1
Yokich
  • 1,247
  • 1
  • 17
  • 31

2 Answers2

0

To create CustomPagerAdapter please extend the FragmentStatePagerAdapter .

You can follow this : http://developer.android.com/reference/android/support/v13/app/FragmentStatePagerAdapter.html

I was having same problem and it works for me.

If you are still having this problem then please let me know.

Nitesh Singh
  • 328
  • 3
  • 13
  • As I said I need to have support for SDK9, does not v13 mean that it supports a minimum of SDK13? I don't have the problem anymore since I did a work-around using activities. Not as flexible but suiting to the SDK – Yokich Oct 21 '14 at 09:15
0

Query: When You change fragment You call web service. you can use that code in manifest try it.

android:configChanges="orientation|screenSize"
Rohitashv jain
  • 244
  • 1
  • 15
  • I am not sure what you mean by this or how it will help? It has nothing to do with the falsely saved savedstates of a FragmentStatePagerAdaptor. It might solve something for orientation or screenSize changes if I'm guessing correctly- but standard usage would still be the same. – Yokich Oct 21 '14 at 09:17