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

Ribbit app, SectionsPagerAdapter Issue in Android Studio...

I'm following this lesson using Android Studio, I changed the imports and followed all the instructions, but the problem i'm having is, My A.S. Build does not have the "DummyPlaceholder", I switched to eclipse and started the project over, same issue.

Here's my SectionsPagerAdapter code; The error is in the "Return" section. The PlaceholderFragment, this is what i get when i mouse over it(Cannot resolve symbol 'PlaceholderFragment')

public class SectionsPagerAdapter extends FragmentPagerAdapter {

protected Context mContext;

public SectionsPagerAdapter(Context context, FragmentManager fm) {

    super(fm);
    mContext = context;
}

@Override
public Fragment getItem(int position) {

    // getItem is called to instantiate the fragment for the given page.
    // Return a PlaceholderFragment (defined as a static inner class below).
    return PlaceholderFragment.newInstance(position + 1);
}

@Override
public int getCount() {
    // Show 2 total pages.
    return 2;
}

@Override
public CharSequence getPageTitle(int position) {
    Locale l = Locale.getDefault();
    switch (position) {
        case 0:
            return mContext.getString(R.string.title_section1).toUpperCase(l);
        case 1:
            return mContext.getString(R.string.title_section2).toUpperCase(l);
    }
    return null;
}

2 Answers

You need to create 2 Fragment class first as you intend to have 2 fragments from getCount() method.

Use a switch statement to display appropriate fragment base on the tab user selected.

    public Fragment getItem(int position)
    {
        // getItem is called to instantiate the fragment for the given page.
        switch(position)
        {
            case 0: return new InboxFragment();

            case 1: return new FriendsFragment();

        }

        return null;
    }

Ok, I created the two classes and the errors went away. Thanks for the help Peh!