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.
Alex Feinberg2,025 Points
Fragment in the Ribbit login and sign up activities
In the Ribbit Android project, when creating the login and sign up activities with the latest and greatest New Activity wizard, you need to provide a Fragment Layout Name in addition to the Layout name. This results in two files in the layout folder (e.g. activity_login.xml and fragment_login.xml. Fleshing out the fragment_login.xml (as opposed to the activity_login.xml as in the video) is simple, but things start getting tricky when you try to add the OnClickListener in the LoginActivity. The findViewById(R.id.signUpText) method returns null, presumably because that ID does not exist in the activity_login.xml, but is in the fragment_login.xml instead. I've played with the fragment manager to try to find the signUpText TextView from the fragment, but haven't cracked it yet. I'm sure there's an easy way to drill down into the fragment to get the desired view. Right?
Ben JakubenTreehouse Teacher
I'm making some notes about this today and recording a fix next week. I answered your other post first and mentioned some options. I'll copy and paste them in here:
Anyhow, what this means is that the Login and Signup Activities will look a little different. I'm going to records some fixes next week and then we'll pop them in, but in the mean time, check out these instructions on how to remove Fragments (you'll have to scroll down a little). Or you can keep them and make layout changes in the fragment XML files and add code in the Fragment's
onCreateView() method instead of the Activity's
Or a third option: download the project files and continue from there! Hope this helps...
Alex Feinberg2,025 Points
I removed the fragments and all is will. Thanks! I look forward to seeing updates to this or other Android projects which use the new default fragments approach.