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

SectionsPagerAdapter.Java class

Is it OK if i just leave the "SectionsPagerAdapter" in the original MainActivity class as it was created?

Would i have any problems down the line if i don't put it in a separate class file?

1 Answer

Yes you can leave the 'SectionsPagerAdapter' in the original class as it was created. Just remember to switch between your tabs to return your fragments:

public Fragment getItem(int position) {
            switch (position) {
                case 0:
                    return new FragmentOne();
                case 1:
                    return new FragmentTwo();
                case 2:
                    return new FragmentThree();

            }
            return null;
        }

However, it's a better to separate it - follows the single responsibility principle. Makes your code easier to manage and update. Also easier for other developers to work with if you're part of a team. Hope this helps.