3

I have a tabbed activity on Android Studio.I want to open my second tab on startup.How can i do this?

enter image description here

Shabbir Dhangot
  • 8,954
  • 10
  • 58
  • 80
metomero
  • 63
  • 1
  • 11
  • This solution solved my problem ; http://stackoverflow.com/questions/30796710/tablayout-tab-selection – metomero Mar 17 '17 at 21:46

2 Answers2

3

If you are using viewpager then you can simply do

mViewPager.setCurrentItem(n);

where, n = tab no which you want to open as default.

Since it counts from index 0 so in your case n=1, so it will be

mViewPager.setCurrentItem(n);
currarpickt
  • 2,290
  • 4
  • 24
  • 39
MAK
  • 46
  • 3
1

If you are using tabHost then you can simply do-

tabHost.setCurrentTab(1);

just after you set the tabHost in onCreate()

GladiatorAsif
  • 76
  • 1
  • 5