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

Java

why create variable for factBook?

Wouldn't it be better to simply call factBook.getFact() in the SetText method?

    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            // Update the screen with a new fact
            factTextView.setText(factBook.getFact());
        }
    };

1 Answer

Steven Parker
Steven Parker
229,708 Points

As "setText" seems to be designed to allow setting any text, the change you are suggesting would alter what it does. That would be OK this time, but it might keep it from working if called with another argument elsewhere in the code.

If you altered the function, it might be better to give it a different name, like "setFact".