Reputation: 588
How to get active tab position in material tabs?
Any one help me.
Upvotes: 1
Views: 3255
Reputation: 3238
Try this
tabLayout.setOnTabSelectedListener(
new TabLayout.ViewPagerOnTabSelectedListener(viewPager) {
@Override
public void onTabSelected(TabLayout.Tab tab) {
super.onTabSelected(tab);
position = tab.getPosition();
}
});
}
Upvotes: 1
Reputation: 1379
In your Activity implement OnTabChangeListener,
then set the listener for the TabHost tabHost.setOnTabChangedListener(this);
@Override
public void onTabChanged(String id) {
Log.i("INDEX->", "Selected TAB Index - "+ tabHost.getCurrentTab());
}
Upvotes: 1
Reputation: 347
Try this
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.getSelectedTabPosition();
Upvotes: 2
Reputation: 972
tabLayout.setOnTabSelectedListener(
new TabLayout.ViewPagerOnTabSelectedListener(viewPager) {
@Override
public void onTabSelected(TabLayout.Tab tab) {
super.onTabSelected(tab);
currentPage = tab.getPosition();
}
});
}
Upvotes: 3