This is what I was trying to do, The "Tab One" "Tab Two" as my Tabbed Page Title. Ignore the Toolbar
I created an app that uses tabbed activity, I used the preset tabbed activity in android studio and modified it to my use. But I'm having a problem in showing the tabbed title. I'm working only on 2 tabs for now but i'm planning to add more as I progress.
Here is the codes for my Tabbed Activity Class
public class StudLearnTab extends AppCompatActivity {
private SectionsPagerAdapter mSectionsPagerAdapter;
private ViewPager mViewPager;
String key;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabbed_content);
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
}
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
switch (position){
case 0:
Bundle bundle = new Bundle();
bundle.putString("keys",key);
fragment_tabbed_content tab1 = new fragment_tabbed_content();
tab1.setArguments(bundle);
return tab1;
case 1:
fragment_tabbed_activity tab2 = new fragment_tabbed_activity();
return tab2;
default:
return null;
}
}
@Override
public int getCount() {
// Show 2 total pages.
return 2;
}
@Override
public CharSequence getPageTitle(int position) {
switch (position){
case 0:
return "Content";
case 1:
return "Try Yourself";
}
return null;
}
}
}
My Fragments only contains the constructor and createview but I'll included it here for reference. Both fragments are almost the same.
public class fragment_tabbed_activity extends Fragment {
public fragment_tabbed_activity() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_tabbed_activity, container, false);
return rootView;
}
}