Android : ViewPager Fragments disappear after screen rotation

on Tuesday, February 17, 2015


I have the following problem:


The content of my fragments is dependet on the content of xml files. So in the onStart method of my FragmentActivity I call a method which reads those files and generates fragments and puts them in a list. These fragments hold an ArrayList which contains all the views to display in this fragment.


After generating the fragment-list, I give it into a FragmentPagerAdapter to display them in a ViewPager. At this point, when connecting the ViewPager to the adapter, the onCreateView method of my fragments is called. This is where the views from the above mentioned ArrayList are placed on the containerview.


Thats how it works if the activity is created initially.


When it's restoring it's state, for example after a rotation change, the onCreateView method of my fragments is called before I can even parse the xml files and generate the views to display in my fragments. Therefore the fragments are empty.


0 comments:

Post a Comment