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
MUZ141027 Tapiwa Choga
4,751 PointsUsing 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
Petrea Costin
3,430 PointsThis works: Drawable drawable = getResources().getDrawable(movie.getImageId()); mMovieImage.setImageDrawable(drawable);
James Simshaw
28,738 PointsHello,
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.
Mr. Valdemar
Courses Plus Student 13,620 PointsDrawable drawable = getResources().getDrawable(XXX.getImageId()); YYY.setImageDrawable(drawable);