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

Ashiwn Ashok
Ashiwn Ashok
6,774 Points

Id 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???

Caleb Kleveter
Caleb Kleveter
Treehouse Moderator 37,862 Points

This is a really good question that I don't have the answer to. I hope you find out!

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! I received your request for assistance :mailbox:. 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! :sparkles:

Ashiwn Ashok
Ashiwn Ashok
6,774 Points

Thank you for your reply.