package com.example.app_10p5; import android.content.Intent; import android.os.Bundle; import android.support.design.widget.TabLayout; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.Fragment; import android.support.v4.view.ViewPager; import android.view.View; /** * Created by beaus on 24/04/2016. */ public class MainActivite extends FragmentActivity { @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.layout_main); TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout); tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE); tabLayout.addTab(tabLayout.newTab().setText("Commande")); tabLayout.addTab(tabLayout.newTab().setText("Rechargement")); tabLayout.addTab(tabLayout.newTab().setText("Création")); tabLayout.addTab(tabLayout.newTab().setText("Vidange")); tabLayout.addTab(tabLayout.newTab().setText("Admin")); tabLayout.setTabGravity(TabLayout.GRAVITY_FILL); final ViewPager viewPager = (ViewPager) findViewById(R.id.pager); final PagerAdapter adapter = new PagerAdapter (getSupportFragmentManager(), tabLayout.getTabCount()); viewPager.setAdapter(adapter); viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { viewPager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(TabLayout.Tab tab) { } @Override public void onTabReselected(TabLayout.Tab tab) { } }); } public void valideCommande(View v) { Intent intent = new Intent(this, CarteActivite.class); startActivity(intent); } }