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 trialSohale Vu
18,322 PointsTrouble with the Understanding the rest of the pieces code challenge
I have been trying to figure out where to place
mDeleteButton = (Button)findViewById(R.id.deleteButton);
to make the first part of the code challenge to work, but nothing seems to take it. I'm not sure what I am doing wrong. I believe that this code is correct.
4 Answers
Ernest Grzybowski
Treehouse Project ReviewerWhat error are you getting from the challenge engine?
If you are working with fragments, remember that you will have to call findViewById()
from another view. It would look something like:
mDeleteButton = (Button) rootView.findViewById(R.id.deleteButton);
Edit: Make sure that you put your code that handles Views in onCreateView(). This is what you have to do for Fragments, unlike Activities.
Timothy Boland
18,237 PointsI think this code challenge is a little premature, because the video dosen't discuss how to use onCreateView yet
Sohale Vu
18,322 PointsThe error that I get when my put my code anywhere but inside of the onCreate method is Bummer! There is a compiler error. Please click on preview to view your syntax errors!
When I put my code inside the onCreate method I get
Bummer! Make sure you are setting the button in the correct lifecycle method for a Fragment!
Ernest Grzybowski
Treehouse Project ReviewerEdited my original answer.
Sohale Vu
18,322 PointsThank you for your help! So for fragments I need to set the buttons in the onCreateView()?
Ernest Grzybowski
Treehouse Project ReviewerYep! Almost like how in Activities, you have to call setContentView()
before you can start calling on UI elements.
Junior Tan
1,893 PointsJunior Tan
1,893 Pointswas rootView mentioned in the vid?