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 Build a Simple Android App Basic Android Programming Accessing Views in Code: Assigning Variables

mariko muranishi
mariko muranishi
860 Points

what is the ID?

I think I understand what the ID is by intuition, but I don't understand what the ID is more. please explain it more concretely.

1 Answer

Evgeniia Vakarina
Evgeniia Vakarina
3,317 Points

ID is used in XMLs so you can access your views in java files. This all is done by the magic of R - the class that is built automatically by Android Studio and that registers all the resources (stuff in res folder) you want to access from a java class. E.g. if you need to access a picture you can put it in drawable folder and then access it from an activity by R.drawable.[file_name], by the same logic you access the views from XML - R.layout.[id]