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!

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 an Interactive Story App (Retired) Finishing the User Interface Loading the First Page

method deprecated

When i am creating a new drawable object and getting resources as image I am getting a deprecated method name getDrawable()

<p> Drawable drawable = getResources().getDrawable(page.getImageId()); </P>

2 Answers

Valerie Makumire
Valerie Makumire
3,262 Points

For non-themed drawables use this instead:

ResourcesCompat.getDrawable(getResources(), page.getImageId(), null);
cheng zheng
cheng zheng
Courses Plus Student 1,288 Points

not working, not sure why.

private void loadPage(int choice) {
        mCurrentPage = mStory.getPage(choice);
        Drawable drawable =  ResourcesCompat.getDrawable(getResources(), mCurrentPage.getImageId(), null);
        // ..... 
Trainer Workout
Trainer Workout
22,341 Points

Try this

Drawable mDrawable = ContextCompat.getDrawable(this, mPage.getImageId());

the instructions do not say call the member variable when setting mImageView.setImageDrawable(drawable)); very close though. This works for me Drawable drawable = ContextCompat.getDrawable(this, page.getImageID());