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

mFactTextView = findvVewByid(R.id.factTextView); question please

Hello,

i dont actully understand what this method does: mFactTextView = findvVewByid(R.id.factTextView);

i learn java but this is somethig new to me does somebody can explain it to me please?

2 Answers

You're setting a variable, to hold a reference to the view.

So, on your layout you have a view(textview) with an id of factTextView. Think of the id as like a description of the thing. so if we were in a room and I asked you to findpersonbyhaircolor('red') you'd go off and look for a person with red hair. Now suppose there could only be one person with red hair (because this is a weird party). You'd go find that person and bring them back to me. and then I could tell them to do stuff. whereas I couldn't before because I didn't know where they were.

same thing here. you're telling the code "hey go find the view with this id" and then once it finds it it places a reference to it in the variable mFactTextView. And then you can tell it to do stuff like .setText().

'''java mFactTextView = findvVewByid(R.id.factTextView); '''

so factTextView suppost to be the value of mFactTextView ?

no, mFactTextView IS factTextView. you use it in the code like you would in the editor. like in the editor you'd set the text property to "test text" .. and in the code you'd use mFactTextView.setText("test text"). it's exactly the same, except one is done in the editor and one is done in code. the advantage of code being that you can change it at runtime(when the app is running on a user's device).

oh now i go it thank you very much !