Tabs In A Class That Extends Fragment
I'm reading many tutorial how to implement tabs in a class that extends FragmentActivity,but no one about how to implement tabs in a class that extends Fragment I created with Andr
Solution 1:
For that you can use FragmentTabHost
class, that let's you add tabs to your Fragment
, just as you do for Activities
.
Here's an example:
publicclassFragmentTabsFragmentSupportextendsFragment {
privateFragmentTabHost mTabHost;
@OverridepublicViewonCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mTabHost = newFragmentTabHost(getActivity());
mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.fragment1);
mTabHost.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple"),
FirstFragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("contacts").setIndicator("Contacts"),
SecondFragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("throttle").setIndicator("Throttle"),
ThirdFragment.class, null);
return mTabHost;
}
@OverridepublicvoidonDestroyView() {
super.onDestroyView();
mTabHost = null;
}
}
For more information, check the official documentation.
Post a Comment for "Tabs In A Class That Extends Fragment"