My HomeActivity extends AppCompatActivity that uses 2 tabs.
public class HomeActivity extends AppCompatActivity {
private SectionsPagerAdapter mSection
Depends on what you want. If you just want to know if the tab page changes, or find out which tab position was selected, use:
mViewPager.setOnPageChangeListener(new OnPageChangeListener() {
public void onPageScrollStateChanged(int state) {
}
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
public void onPageSelected(int position) {
}
});
Else, if you want to keep track of the tab itself, you will have to implement TabLayout.OnTabSelectedListener
like this:
public class HomeActivity extends AppCompatActivity implements TabLayout.OnTabSelectedListener
And add this methods to your HomeActivity class:
@Override
public void onTabSelected(TabLayout.Tab tab) {
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}