IllegalStateException: The application’s PagerAdapter changed the adapter’s content without calling PagerAdapter#notifyDataSetChanged

I had a hard time making my ViewPager working. At the end, it seems that the example in the documentation is wrong. The addTab method should be as follows: public void addTab(Tab tab, Class<?> clss, Bundle args) { TabInfo info = new TabInfo(clss, args); tab.setTag(info); tab.setTabListener(this); mTabs.add(info); notifyDataSetChanged(); mActionBar.addTab(tab); } Notice the order of the … Read more

How to get existing fragments when using FragmentPagerAdapter

Summary of the problem Note: In this answer I’m going to reference FragmentPagerAdapter and its source code. But the general solution should also apply to FragmentStatePagerAdapter. If you’re reading this you probably already know that FragmentPagerAdapter/FragmentStatePagerAdapter is meant to create Fragments for your ViewPager, but upon Activity recreation (whether from a device rotation or the … Read more

What is the difference between FragmentPagerAdapter and FragmentStatePagerAdapter?

Like the docs say, think about it this way. If you were to do an application like a book reader, you will not want to load all the fragments into memory at once. You would like to load and destroy Fragments as the user reads. In this case you will use FragmentStatePagerAdapter. If you are … Read more

How to implement a ViewPager with different Fragments / Layouts

As this is a very frequently asked question, I wanted to take the time and effort to explain the ViewPager with multiple Fragments and Layouts in detail. Here you go. ViewPager with multiple Fragments and Layout files – How To The following is a complete example of how to implement a ViewPager with different fragment … Read more