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.

Android Build an Interactive Story App Intents and Multiple Activities Getting Text from an EditText

Arcee Palabrica
Arcee Palabrica
8,100 Points

Clarification 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

Hi 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. :+1:

Steve.

No problem! :+1: :smile:

Garry Barlow
Garry Barlow
2,210 Points

I had the same issues. I capitalised the S in StartButton and it worked??

Hi 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
Garry Barlow
2,210 Points

Great Thanks, Steve. Back on track!

:+1: :+1: :+1: :+1: