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 trial

Android

factlabel.setText.(fact);

What that does? why we need it in our code? it doesnt change anything at the screen. we say setText that means write something. its kinda confusing

3 Answers

Well the line above sets the fact that you have randomly selected from the array using random() into your factlabel textview Which is displayed on the screen

i havent use random() anywhere.. and i still dont get it :S

If you take a look at your code (in your FunFactsActivity.java file), you can see that the variable factLabel is being set to refer to a TextView with an id of factTextView. Heading over to your activity_fun_facts.xml file, we can see which TextView we are referring to. (It is the TextView that you will be using to display the fun facts.)

Now, back to the code in FunFactsActivity.java, we can see the part that you were confused about: factLabel.setText(fact). All this is doing is updating the TextView's text to a new fact (the fact is retrieved using getFact() on mFactBook in the line above).

So, each time the showFactButton is clicked, the OnClickListener will set the TextView to display a new fact. Hope this helps! Let me know if you need more clarification.

generally i know some things about coding but even if these are starting coding its hard to understand.. i will think it for some days.. and if i need any help i will let you know..

thanks very much