I'm making a new app, using the "Swipe View + Tile Strip" layout, but can't seem to figure out how to actually load different views into the fragments of the FragmentPagerAdapter?
Any help on this would be great (I'm still quite new to android development, so go easy ;) )
Create a class that extends FragmentPagerAdapter
.
Override getItem()
and return a different fragment for each position.
Try something like this:
public class MyCustomFPAdapter extends FragmentPagerAdapter{
public MyCustomFPAdapter (FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
if (position == 0) {
return Fragment0.newInstance();
} else if (position == 1) {
return Fragment1.newInstance();
} else if (position == 2) {
return Fragment2.newInstance();
} else if (position == 3) {
return Fragment3.newInstance();
} else {
return DefaultFragment.newInstance();
}
}
}
In a FragmentPagerAdapter you don't load Views, but Fragments.
Read the official documentation of FragmentPagerAdapter, which has a nice tutorial also. This is the first step to understand this Pager.
http://developer.android.com/reference/android/support/v4/app/FragmentPagerAdapter.html
Good luck!