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 trialIvan Gadza
1,539 PointsI dont understand what TextView is and can somebody explain this code.
Can somebodey explaing what textview is and this code.Thanks.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fun_facts);
final TextView factLabel = (TextView) findViewById(R.id.factTextView);
Button showFactButton = (Button) findViewById(R.id.showFactButton);
View.OnClickListener listener = new View.OnClickListener()
3 Answers
Ivan Gadza
1,539 PointsThanks
william mark
Courses Plus Student 367 Pointsyou declare a integer as int x=10; similarly we declare a TextView as "TextView factLabel " .Here TextView is a Data type like int,String,char etc.
Dan Johnson
40,533 PointsA TextView is simply used to display text to the user. In this case the variable factLabel is being assigned to a TextView that was defined in the layout XML file.
protected void onCreate(Bundle savedInstanceState) { //When this object is created...
super.onCreate(savedInstanceState); //Call the parent classes onCreate
setContentView(R.layout.activity_fun_facts); //Use the activity_fun_facts layout to describe the UI
final TextView factLabel = (TextView) findViewById(R.id.factTextView); //Get the TextView with the id of factTextView in the layout file.
Button showFactButton = (Button) findViewById(R.id.showFactButton); //Get the Button with the id of showFactButton in the layout file.
View.OnClickListener listener = new View.OnClickListener() { //Define a new listener to respond when a user clicks on something (such as the showFactButton).
//...