Search code examples
androidandroid-design-libraryandroiddesignsupport

How to get the current selected item position using TabLayout in Android Design Library


I am using the android design library TabLayout in that how can I get the current selected item tab position.

  ViewPager pager = (ViewPager) view.findViewById(R.id.pager);      
  MyPagerAdapter adapter = new MyPagerAdapter(getChildFragmentManager());
  pager.setAdapter(adapter);
  tabLayout.setupWithViewPager(pager);

Solution

  • As of version 22.2.1 of the Support library the TabLayout has a method getSelectedTabPosition.

    Source 1 | Source 2