in my android app, i set an tab layout like this:
final TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout); tabLayout.addTab(tabLayout.newTab().setText("TAB 1")); tabLayout.addTab(tabLayout.newTab().setText("TAB 2")); tabLayout.addTab(tabLayout.newTab().setText("TAB 3")); i would like to disable tab 2 and tab 3. i try this and it works:
tabLayout.getChildAt(1).setEnabled(false); tabLayout.getChildAt(2).setEnabled(false); but i also would like to set an toast feedback, if somebody tap on a disable tab, like "This Tab is not unlocked"
for this i try to set an onclicklistener for tab 2 and 3. but this listener doesn't work, if I disable the tab with the code before.
have anybody an idea how i can solve this problem?
UPDATE
@Override public void onTabSelected(TabLayout.Tab tab) { if (tab.getPosition() == 1) { viewPager.setCurrentItem(0); TabLayout.Tab tab1 = tabLayout.getTabAt(0); tab1.select(); } else { viewPager.setCurrentItem(tab.getPosition()); } }