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 trialArnaud TOUTAIN
957 PointsWhat are the modification needed to go through this step using Android Studio ?
I don't how to deal with the PlaceHolderFragment...
2 Answers
Mauricio Liu
1,141 PointsStatic classes have to be nested inside other classes. PlaceholderFragment is originally a nested class inside MainActivity class, when extracting it you can nest it inside the newly created SectionsPagerAdapter class for it to work.
Tyrel Hiebert
14,739 PointsI struggled with this for a few hours. Finally, Ben's answer here really helped me.
In SectionsPagerAdapter.java, change PlaceholderFragment to MainActivity.PlaceholderFragment so that it looks like this
@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 MainActivity.PlaceholderFragment.newInstance(position + 1);
}
This allows it to reference the MainActivity for the PlaceholderFragment class.
Then in your MainActivity.java, make sure that your imports for Fragment, FragmentManager and FragmentPagerAdapter are referencing the v4 support library, like this
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
Instead of any of them being
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentPagerAdapter;
In the notes for this video, it tells you to update the FragmentActivity import, but not the others.
You may not need FragmentManager as it is grey (unused) in my project at this stage, but I left it there anyway as I am just glad that my app will run now.
I hope this helps. I was stuck with this same problem and this seemed to do the trick!
David Barnes
1,740 PointsDavid Barnes
1,740 PointsSeconding this post, looks like it may have changed again, I'm Googling but coming up empty at the moment