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

Simplified Coding


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);

setContentView()R.Layout.activity_main);

// add toolbar to activity

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

setSupportActionBar()Toolbar);

// starting tabulation

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

// Add tab using AddTab () method

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

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

Tablat.AddTab()Tablat.new 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

Observer.setAdapter()Adopter);

// Adding onTabSelectedListener to swipe ideas

Tablat.setOnTabSelectedListener()this);

}

@ 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

Be the first to comment

Leave a Reply

Your email address will not be published.


*