package com.example.tabfragment;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import java.util.ArrayList;

class ViewPagerAdapter extends FragmentPagerAdapter {

    ArrayList<String> arraytitles = new ArrayList<String>();
    ArrayList<Fragment> arrayfragments = new ArrayList<Fragment>();

    public ViewPagerAdapter(FragmentManager fm) {

        super(fm);
    }

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

    @Override
    public CharSequence getPageTitle(int position) {

        return arraytitles.get(position);
    }

    @Override
    public int getCount() {

        return arrayfragments.size();
    }

    public void addfragment(Fragment fragment, String title) {
        arraytitles.add(title);
        arrayfragments.add(fragment);
    }
}
