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 trialCarl Sergile
16,570 PointsDon't really get this question.
This is in reference to part 2 of this exercise.
For 1. I copied and pasted ListFragment fragment = new ListFragment(); FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.add(R.id.placeHolder, fragment); fragmentTransaction.commit();
I think I did exactly what it told me to do, but the question didn't say anything about using FragmentManager(which I used). Since I don't know any other way to do this then, I don't know how to exactly answer this question.
Any help/advice would be great
public class NewsFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_news, container, false);
;
return view;
}
}
public class MainActivity extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListFragment fragment = new ListFragment();
fragment.add(R.id.placeholder, fragment);
}
}
2 Answers
Evan Demaris
64,262 PointsHi Carl,
You've got an extra semicolon on an empty line in your NewsFragment
, and fragment
should be a NewsFragment
instead of a ListFragment
. Otherwise, your code looks sound.
Hope that helps!
Seth Kroger
56,414 PointsBe sure the names of things match the code you are copy/pasting into. The class in the challenge is called NewsFragment, not ListFragment. Also check the capitalization of "placeholder".