Welcome to the Treehouse Community
Looking to learn something new?
what actually happens if i removed the line 20 (TextView)
in the line 21, i know that we added it to make a sound for the button. but in the line 20, i can't figure why and what it's for, i removed it and i ran the app and it worked fine. please explain it in another way.
If the line 20 you're referring to is:
Button showFactButton = (Button) findViewById(R.id.showFactButton);
What it is doing is giving is finding the item in our view by the given identifier(which was defined in XML), and creating a variable for it that we can interact with in the code. If we didn't have that line, we wouldn't be able to run any code involving that button. So this way we have something we can actually use to set the onclicklistener.
Michael Waihura6,963 Points
Line 20 : TextView factLabel = (TextView) findViewById(R.id.factTextView); Removing this line does not affect running the app as it has not yet been used yet.We've only declared the TextView and initialised it by referencing the value from xml.It actually looks greyed out as it has not yet been used yet.Am sure we'll use it in the upcoming videos.