Mike
Mike

Reputation: 6839

How can I switch from the old tabhost to swipe tabs in Android?

I am currentley using the old tabHost to hold a hand full of different fragments as tabs. How can I easily switch this over to the newer swipe tabs?

public class StatisticsTab extends Fragment  {


    private FragmentTabHost mTabHost;

    //Mandatory Constructor
    public StatisticsTab() {
    }

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_tabs,container, false);

        mTabHost = (FragmentTabHost)rootView.findViewById(android.R.id.tabhost);
        mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent);




        mTabHost.addTab(mTabHost.newTabSpec("Basic").setIndicator("Basic"),
                StatisticsPage.class, null);
        mTabHost.addTab(mTabHost.newTabSpec("Brewery").setIndicator("Brewery"),
                BreweryStatistics.class, null);
        mTabHost.addTab(mTabHost.newTabSpec("Style").setIndicator("Style"),
                StyleStatistics.class, null);
        mTabHost.addTab(mTabHost.newTabSpec("Taste").setIndicator("Taste"),
                TasteStatisticsPage.class, null);



        return rootView;
    }




}

Upvotes: 0

Views: 321

Answers (1)

iStar
iStar

Reputation: 1120

Try PagerSlidingTabStrip(https://github.com/astuetz/PagerSlidingTabStrip). An interactive indicator to navigate between the different pages of a ViewPager. It works awesome for me.

Upvotes: 1

Related Questions