Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Ayman Bitar
Ayman Bitar
9,462 Points

Android Navigation (Tabs, Fragments)

Hello,

So far my app, displays a list of items, that when we click on any of the item it takes us to a content page of that list item.

Now i would like to add different categories that i will retrieve from my website.

How can i keep what i have, and just different categories?

I looked around and there are several things out there, some use fragments, others just simple tabs, i would like to know which one would be better for me.

I tried to play around with the fragments but i kinda hit a wall, since my current application extends ListActivity, and if i need to use fragments, i'll have to extend Fragment. And in java/android we can't extend more than one, so the context will change and a lot of functions that i already have don't work.

Thank you in advance.

Best, Ayman

2 Answers

Ayman Bitar
Ayman Bitar
9,462 Points

Hi Ben,

My only problem is actually, change the type of my class.

Basically what i have at the moment is a class that extends listActivity, but in order to use the fragment in order to use tabs or any other sort, the class has to extend FragmentActivity.

If i change the ListActivity to FragmentActivity, what should i change in my current code in order for it to stay working the same way it is at the moment.

Thanks, Ayman

Ben Jakuben
Ben Jakuben
Treehouse Teacher

They are pretty similar. This StackOverflow answer has a pretty good recap of what you need to do to convert a ListActivity to a FragmentActivity: http://stackoverflow.com/a/11784442/475217

Ayman Bitar
Ayman Bitar
9,462 Points

Hi Ben,

It worked perfectly.. Thank you very much! I'll let you know how it goes from there.

Best, Ayman

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

It sounds like adding tabs would be a good place to start, but it's not exactly easy with Fragments. Off the top of my head I don't have a good tutorial to point you to, though we will try to cover this exact thing in the next Android project. You could try a dropdown in the Action Bar that lets you change categories.

Here's one example that might help: http://thepseudocoder.wordpress.com/2011/10/04/android-tabs-the-fragment-way/