3

Hi Friends i want to create tab's in project. For making tab there is two way which i found

1) Extends the activity class with TabActivity class which is deprecated as i seem this is a easy way but don't why it is deprecated so i want to know whether any other class or any alternative for that class.

2) Create individual activity for every tab which lengthy but convenient way but still feels TabActivity is fast one.

I was wondering if anybody could tell me, Thanks

Love Garg
  • 406
  • 1
  • 5
  • 17

2 Answers2

3

For making tab there is two way which i found

You can also:

  • Use a ViewPager with a tabbed indicator, such as PagerTabStrip, the TabPagerIndicator from the ViewPagerIndicator project, PagerSlidingTabStrip, etc.

  • Use tabs in the action bar (note: these will convert into a drop-down list in some device sizes and orientations)

  • Use FragmentTabHost

  • Use TabHost and TabWidget in a regular Activity

The following sample projects demonstrate:

Note that the first three samples all use ActionBarSherlock, so they run on Android 2.x devices. The fourth one should run on anything from Android 1.0 onwards.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • i'll tried FragmentTabHost but it is not supported in mostly previous android version. Do you have any link or more information regarding FragmentTabHost. – Love Garg Jun 29 '13 at 12:01
  • @LoveGarg: `FragmentTabHost` is part of the Android Support package and should work back to API Level 4: http://developer.android.com/reference/android/support/v4/app/FragmentTabHost.html – CommonsWare Jun 29 '13 at 12:04
  • But in development we give minimum require sdk we give android 2.2 which is not supported by it is there any working way to use it in below version also. And thanks for your quick reply!!!! – Love Garg Jun 29 '13 at 12:08
  • @LoveGarg: "which is not supported by it is" -- the SupportV4Demos project, from Google, shows a few samples of `FragmentTabHost`, and their project has an `android:minSdkVersion` of `4`: https://github.com/android/platform_development/tree/master/samples/Support4Demos – CommonsWare Jun 29 '13 at 16:01
2

use Fragments as an alternative of TabActivity . To get a feel like Tabs you can do this. Use a FragmentActivity. Add different Fragments in it. And use ViewPager to switch between different fragments.

stinepike
  • 54,068
  • 14
  • 92
  • 112