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 Build a Self-Destructing Message Android App Using Fragments for Tabs Modifying Tabs from the Template

Now set the title for the second tab to be "Black".

help

PagerAdapter.java
import android.support.v4.app.FragmentPagerAdapter;

public class PagerAdapter extends FragmentPagerAdapter {

    // Some code omitted!

@Override
public int getCount() {
    return 4;
}

@Override
public CharSequence getPageTitle(int position) {
    switch (position) {
        case 0:
            return "Coffee";
        case 1:
            return "Rooibos";
        case 2:
            return "Green";
        case 3:
            return "Herbal";
    }
    return null;
}
} 

1 Answer

Harry James
Harry James
14,780 Points

Hey there!

We're setting the titles for the tabs here:

@Override
public CharSequence getPageTitle(int position) {
    switch (position) {
        case 0:
            return "Coffee";
        case 1:
            return "Rooibos";
        case 2:
            return "Green";
        case 3:
            return "Herbal";
    }
    return null;
}

So, you should be able to work out where the 2nd tab is (Hint! The first tab is at the 0th position!) and change its return statement to whatever the title of the tab should be. Right now, the titles for the tabs are Coffee, Rooibos,, Green and Herbal.


Hope it helps and if you have any more questions/problems, give me a shout :)