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

Arcee Palabrica
Arcee Palabrica
8,099 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

Steve Hunter
MOD
Steve Hunter
Treehouse Moderator 57,557 Points

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.

Garry Barlow
Garry Barlow
2,210 Points

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

Steve Hunter
Steve Hunter
Treehouse Moderator 57,557 Points

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!