package com.example.jelica.tabs;

import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ViewPager viewPager = findViewById(R.id.container);
        setupViewPager(viewPager);

        TabLayout tL = findViewById(R.id.tabs);
        tL.setupWithViewPager(viewPager);
    }

    private void setupViewPager(ViewPager vP){
        MyPageAdapter mpa
        = new MyPageAdapter(getSupportFragmentManager());

        mpa.addFragment(new Tab1Fragment(), "Tab1");

        mpa.addFragment(new Tab2Fragment(), "Tab2");

        mpa.addFragment(new Tab3Fragment(), "Tab3");

        vP.setAdapter(mpa);

    }
}
