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

For non-themed drawables use this instead:

ResourcesCompat.getDrawable(getResources(), page.getImageId(), null);

not working, not sure why.

private void loadPage(int choice) {
        mCurrentPage = mStory.getPage(choice);
        Drawable drawable =  ResourcesCompat.getDrawable(getResources(), mCurrentPage.getImageId(), null);
        mImageView.setImageDrawable(drawable);
        // ..... 
}

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());