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

Using getDrawable(int id)

Kindly assist on the weather up setting views-with-data. Challenge tast 2 of 2.

Now let's set the image using the Movie method that gets the appropriate ID. Note: getDrawable(int id) was deprecated in API 22, but it's ok to use it here.

3 Answers

This works: Drawable drawable = getResources().getDrawable(movie.getImageId()); mMovieImage.setImageDrawable(drawable);

Hello,

The challenge is likely still setup to be referencing the older APIs where getDrawable wasn't deprecated.

If you are coding something to include the more modern APIs, you can use ContextCompat.getDrawable(Context, int) where you supply your current Context(likely the Activity you are in), and the id of the drawable you are wanting to reference.

Drawable drawable = getResources().getDrawable(XXX.getImageId()); YYY.setImageDrawable(drawable);