Search code examples
androidswipeandroid-tabs

Android swipe and tabs ui - what is "best practice" and up to date?


I have used in the past often the "Android ActionBar FragmentPagerAdapter and ViewPager" which seems a little out of date - is there a newer, more advanced/better guideline/technique to do those stuff ?

Android 4.4

for example:

private ViewPager viewPager;
private TabsPagerAdapter mAdapter;
private ActionBar actionBar;

and the TabsPagerAdapter class:

public class TabsPagerAdapter extends FragmentPagerAdapter {

    FrontEndController context;
    WearListFragment wearListFragment;
    MobileListFragment mobileListFragment;
    FavouriteListFragment favouriteListFragment;
    AdvancedControlFragment advancedControlFragment;
    ControlFragment controlFragment;
    SetupFragment setupFragment;
    StatusFragment statusFragment;

        public TabsPagerAdapter(FragmentManager fm,FrontEndController context) {
            super(fm);
            this.context =context;

        }

    // "Setup", "Advanced","Favourite","Status","Control", "Mobile", "Wear"

    @Override
        public Fragment getItem(int index) {

            switch (index) {
                case 0:
                    //Setup
                    setupFragment = new SetupFragment();
                    setupFragment.setContext(context);
                    return setupFragment;

                case 1:
                    advancedControlFragment = new AdvancedControlFragment();
                    advancedControlFragment.setContext(context);
                    return advancedControlFragment;


                case 2:
                    favouriteListFragment= new FavouriteListFragment();
                    favouriteListFragment.setContext(context,this);
                    return favouriteListFragment;


                case 3:
                    statusFragment = new StatusFragment();
                    statusFragment.setContext(context);
                    return statusFragment;

                case 4:
                    controlFragment = new ControlFragment();
                    controlFragment.setContext(context);
                    return controlFragment;


                case 5:
                    mobileListFragment = new MobileListFragment();
                    mobileListFragment.setContext(context);
                    return mobileListFragment;

                case 6:
                    wearListFragment = new WearListFragment();
                    wearListFragment.setContext(context);
                    return wearListFragment;
            }

            return null;
        }

        @Override
        public int getCount() {
            // get item count - equal to number of tabs
            return 7;
        }

    public WearListFragment getWearListFragment() {
        return wearListFragment;
    }

    public MobileListFragment getMobileListFragment() {
        return mobileListFragment;
    }

    public FavouriteListFragment getFavouriteListFragment() {
        return favouriteListFragment;
    }


}

Solution

  • You have a lot of posibilities:

    Default Android tabs and viewpager:

    Creating Swipe Views with Tabs

    Plugins (recommended):

    Most famous:

    PagerSlidingTabStrip

    enter image description here enter image description here

    implement guide: https://stackoverflow.com/questions/26178838/pagerslidingtabstrip implement-guide

    others:

    List of ViewPager plugs