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

DEXUAN LI
DEXUAN LI
6,222 Points

do i need to write (someView) before findViewById

do i need to cast the view in the newest version of Android Studio? Like do need to write (someView) before findViewById(R.id.someView);

1 Answer

Hello!

You have to cast the type everytime you bind a view to a variable, like so:

TextView someView = (TextView) findViewById(R.id.someView);

The basic syntax is:

// view_object_name variable_name = (view_object_name) findViewById(R.id.view_object_id);

Hope it helped!