Android TabLayout Example using ViewPager and Fragments – Android Coding by DMTechnolab

The package The trap.Simplified coding.androidtablayout;

Import Android.Support.The design.Widget.Tablaout;

Import Android.Support.v4.Opinion.Observer;

Import Android.Support.v7.App.AppCompatActivity;

Import Android.The.Bundle;

Import Android.Support.v7.Widget.Toolbar;

// Implementing the interface ontabsledleastener for our mainactivity

// This interface will help swipe ideas

public class Main activity Is spread AppCompatActivity To apply Tablaout.OnTabSelectedListener{{

// this is our table

Private Tablaout Tablat;

// this is our perspective

Private Observer Observer;

@ Override

Protected Zero Go ahead()Bundle saveInstanceState) {{

Super.Go ahead()saveInstanceState);


// add toolbar to activity

Toolbar Toolbar = ()Toolbar) findViewById()R.Id.Toolbar);


// starting tabulation

Tablat = ()Tablaout) findViewById()R.Id.Tablat);

// Add tab using AddTab () method

Tablat.AddTab() tab()).Settext()“Tab 1”));

Tablat.AddTab() tab()).Settext()Tab 2));

Tablat.AddTab() tab()).Settext()Tab 3));

Tablat.Settag gravity()Tablaout.GRAVITY_FILL);

// Initial ViewPager

Observer = ()Observer) findViewById()R.Id.Pager);

// build our pager adapters

Pager Adopter = New Pager()getSupportFragmentManager()), Tablat.getTabCount()));

// add adapter to pager


// Adding onTabSelectedListener to swipe ideas



@ Override

public Zero onTabSelected()Tablaout.The tab The tab) {{

Observer.setCurrentItem()The tab.getPosition()));


@ Override

public Zero onTabUnselected()Tablaout.The tab The tab) {{


@ Override

public Zero onTabReselected()Tablaout.The tab The tab) {{



Source link

About dmtechnolab

Check Also

Simplified Coding

Android Hilt Tutorial – Injecting Dependencies with Hilt – Android Coding by DMTechnolab

You are welcome Android Hilt tutorial. I hope you all are aware of it Dependency …

Leave a Reply

Your email address will not be published. Required fields are marked *