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 The Solution

When we change the text in any TextView, is it necessary for us to convert it into a String. Can I not output an int.

Instead of typecasting a int to a string. I would like to out put the int variable directly in the xyz.setText();.How can it be done

1 Answer

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

The setText() method requires a string. You could make a second variable that converts your int into a string and then pass that to setText(). Something like this will work:

                public void onClick(View v) {
                    String myString = Integer.toString(ct);

But it's an additional line, so you have to decide if compared to ct + "" this is more readable or not :)