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 trialArcee Palabrica
8,100 PointsClarification on startButton
Just wanna clarify this one...
startButton /*1st*/ = (Button) findViewById(R.id.startButton/*2nd*/);
the 1st startButton is the reference to Button and the 2nd one is the id right? coz in the previous course we made use of the 'm' convention this time there's none.
3 Answers
Steve Hunter
57,712 PointsHi there,
The first one is how the Java code refers to your GUI element, the second is what the XML references the element with. So, you hook up one to the other, allowing your code to use that element of the GUI.
In short, yes, your understanding is correct.
Steve.
Garry Barlow
2,210 PointsI had the same issues. I capitalised the S in StartButton and it worked??
Steve Hunter
57,712 PointsHi Garry,
If you declared the button at the top of your code with a capital S:
Button StartButton;
Then you can initialize it further down using the same name:
StartButton = (Button) findViewById(R.id.startButton);
The two references need to match. The convention is to not use a capitalised initial letter for variables/instances; the capital letter is reserved for class names and some datatypes, e.g. String
.
Steve.
Garry Barlow
2,210 PointsGreat Thanks, Steve. Back on track!
Steve Hunter
57,712 Points
Arcee Palabrica
8,100 PointsArcee Palabrica
8,100 PointsSteve Hunter thanks man. :)
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsNo problem!