So I created an Android application project using ActionBar Tabbed Activity using ViewPager. I've also created two fragment classes and attached corresponding fragment layout with them. As the respective tab is selected I return fragment to SectionsPagerAdapter.
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a PlaceholderFragment (defined as a static inner class below).
switch (position) {
case 0:
return new fragmentAddSize();
case 1:
return new fragmentMySizes();
}
return null;
}
}
Now I have some questions about this. I was under the impression that every time a tab is selected, it calls the fragment class and goes into the onCreateView of the fragment but it only happens once.
What I want to achieve is to know when the tabs are selected and the corresponding fragment is in view. So that everytime i switch tabs it just pops a tab sying you are in tab 1 or tab2.