Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Trouble 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.
What 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 Boland18,237 Points
I think this code challenge is a little premature, because the video dosen't discuss how to use onCreateView yet
The 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!
Thank you for your help! So for fragments I need to set the buttons in the onCreateView()?