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 trialAshiwn Ashok
6,774 PointsId type of the resources under drawable
Why is the id type of the resources under the drawable resources taken as of type integer and not String? When we input R.drawable.resource_id , here android studio ask that resource_id be of type integer, whereas we end up giving the name of the resource which is a String. Why is this so???
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! I received your request for assistance . I hope I'm understanding your question correctly. Android takes all resources and keeps track of them using an unique identifier which it calls simply "id". These identifiers are integers. The getDrawable
method can accept an integer and also a theme.
The name of a resource is a string. But the id of a resource is an integer.
Here you can find the documentation on Resources
Here you can read more about getting the Resource name
Hope this helps!
Ashiwn Ashok
6,774 PointsThank you for your reply.
Caleb Kleveter
Treehouse Moderator 37,862 PointsCaleb Kleveter
Treehouse Moderator 37,862 PointsThis is a really good question that I don't have the answer to. I hope you find out!