I have an Activity with a layout that contains 2 Fragments next to each other. In each Fragment, I have a ViewPager. Since I need both Fragments to look the same way, I use the same layout XML for both, which contains a ViewPager.
Now when I test the app, only the ViewPager of the first Fragment seems to work. The second Fragment shows a PagerTitleStrip, and I can flip through it, but it doesn't show the Fragments in the ViewPager.
Why isn't the second ViewPager showing the Fragments too? What is causing this? Is the problem that they use the same layout? Isn't it a different Object anyway?
The layout that the 2 Fragments in the Activity share looks like this:
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.view.PagerTitleStrip
android:id="@+id/search_mapping_pager_title_strip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#33b5e5"
android:paddingBottom="4dp"
android:paddingTop="4dp"
android:textColor="#fff" />
</android.support.v4.view.ViewPager>
Both Fragments instantiate the ViewPager the same way:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_search_mapping,
container, false);
mSectionsPagerAdapter = new SectionsPagerAdapter(mActivity
.getSupportFragmentManager());
mViewPager = (ViewPager) view.findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
return view;
}
EDIT: More code showing my SectionsPagerAdapter
:
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
Fragment fragment = new SuperclassFragment();
Bundle args = new Bundle();
args.putInt(SuperclassFragment.ARG_SECTION_NUMBER, position + 1);
fragment.setArguments(args);
return fragment;
}
...
}
Any tips where I should look for the cause of the bug? I can of course include more code here if necessary.