7

Now that TabActivity is deprecated, what is the proper way to build a tabbed interface using fragments? Every tutorial I have seen takes a different approach. Some of them are supremely complicated pushing a mundane programming topic to the rocket science territory. What gives?

I am coding for ICS Android 4.0.

Thanks.

SnowyTracks
  • 1,965
  • 15
  • 21
RajV
  • 6,860
  • 8
  • 44
  • 62
  • If you want tabwidget with fragment this tutorial might help you http://learnncode.wordpress.com/2013/12/18/how-to-use-tabwidget-with-fragments/ – Prachi Dec 23 '13 at 11:43

1 Answers1

2

The preferred way now is to use the tabs that ActionBar gives you. It's quite easy to set up, given that you like this option. With ActionbarSherlock, you can even port your app all the way back to 1.6.

It's not suitable for every case however. For example, you might need those tabs to be inside a fragment, on a screen that displays multiple fragments at once. In that case, you have to stick with the "deprecated" methods to set up the tabs, using a TabWidget. It's ugly, but possible.

Edit:

Check Jeff's comment. As he pointed out, I was wrong, TabWidget is still perfectly valid, TabAvtivity is the deprecated class here!

Zsombor Erdődy-Nagy
  • 16,864
  • 16
  • 76
  • 101
  • 2
    Thanks. I got tabs working with ActionBar. This document was very useful: http://www.abelski.com/courses/android3ui/actionbar.pdf – RajV Nov 08 '11 at 19:15
  • [`TabWidget`](http://developer.android.com/reference/android/widget/TabWidget.html) is not deprecated, [`TabActivity`](http://developer.android.com/reference/android/app/TabActivity.html) is. The action bar is [not necessarily preferred](http://stackoverflow.com/a/12416617/403455), it depends upon the use, as answered by Adam Powell [Android platform navigation expert](http://www.youtube.com/watch?v=XwGHJJYBs0Q&feature=share&list=PLohJorsmukCY3Au37gitaROt1E2oC_Nh_). – Jeff Axelrod Sep 16 '12 at 22:05