com.davidmiguel.gobees.utils.TabsFragmentPagerAdapter.java Source code

Java tutorial

Introduction

Here is the source code for com.davidmiguel.gobees.utils.TabsFragmentPagerAdapter.java

Source

/*
 * GoBees
 * Copyright (c) 2016 - 2017 David Miguel Lozano
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
 */

package com.davidmiguel.gobees.utils;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.List;

/**
 * Adapter for ViewPager.
 * Control the order of the tabs, the titles and their associated content.
 */
public class TabsFragmentPagerAdapter extends FragmentPagerAdapter {

    private Context context;
    private List<BaseTabFragment> fragments;

    public TabsFragmentPagerAdapter(FragmentManager fm, Context context, List<BaseTabFragment> fragments) {
        super(fm);
        this.context = context;
        this.fragments = fragments;
    }

    @Override
    public int getCount() {
        return fragments.size();
    }

    @Override
    public Fragment getItem(int position) {
        return (Fragment) fragments.get(position);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return context.getString(fragments.get(position).getTabName());
    }
}