11

I create tabs dynamically in a TabActivity. Is there a simple way to ask for the number of existing Tabs?

Janusz
  • 187,060
  • 113
  • 301
  • 369

3 Answers3

18

Maybe a bit of a workaround, but you should be able to use: getTabHost().getTabWidget().getTabCount().

I just tested this in my app and it worked correctly.

See here for more info: http://developer.android.com/reference/android/widget/TabWidget.html#getTabCount()

stephendnicholas
  • 1,810
  • 14
  • 15
6
    TabLayout tabLayout = findViewById(R.id.tabs);
    int totalTabs = tabLayout.getTabCount();
live-love
  • 48,840
  • 22
  • 240
  • 204
3

To get number of Tab Use

tabHost.getTabWidget().getChildCount() // tabHost is the instance of TabHost