I have a simple Activity with TabLayout, ViewPager and 2 Fragments in it. Here\'s my Activity:
public class ManagementCompanyOverviewActivity extends BaseAct
You could also in your adapter's constructor take in the data you want to display in the fragment and set the arguments before returning a new fragment
public class ViewPagerAdapter extends FragmentStatePagerAdapter {
private Weather weather;
ViewPagerAdapter(FragmentManager fm, Weather weather) {
super(fm);
this.weather = weather;
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
Bundle bundle = new Bundle();
WeatherFragment weatherFragment = new WeatherFragment();
bundle.putParcelable("weather", weather);
weatherFragment.setArguments(bundle);
return weatherFragment;
case 1:
return new PoemFragment();
default:
return new EmptyFragment();
}
}