0

This is the line in question. I have it the same way the textbook lists it, but am having issues converting the line to ContextCombat since getDrawable() has been deprecated.

buttonItem.setImageDrawable(getResources().getDrawable(painting.getId()));
Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
London
  • 13
  • 3

1 Answers1

0

You can try using ContextCompat.getDrawable(getActivity(), R.drawable.name);. This will return a styled Drawable as instructed by your Activity's theme. Your code would be more or less as shown below:

buttonItem.setImageDrawable(ContextCompat.getDrawable(getActivity(), painting.getId()));

NOTE: I'm assuming that painting.getId() returns the resource id for the image you want to set as your button's drawable. Also, if you are doing this inside an Activity, you should use the keyword this instead of getActvity().

Talendar
  • 1,841
  • 14
  • 23
  • Thank you! That got rid of that error at least. When I attempt to launch it in debugger mode I get the error "Unfortunately, Renaissance Paintings has stopped." – London Sep 15 '18 at 21:03
  • Is that the only error message you got? Since I don't have access to your program's source code, I need more information in order to understand the problem. – Talendar Sep 15 '18 at 21:09
  • It's working now! It turns out the other issue was that there was a book typo saying linearList instead of linearLayout. Thank you! – London Sep 15 '18 at 21:19
  • I'm glad you managed to make it work! If the answer I gave helped solving your problem I would be glad if you could mark it as your "accepted answer" (by clicking on the grayed out "tick" icon to the left of it). – Talendar Sep 15 '18 at 21:25
  • I really appreciate it! – London Sep 15 '18 at 21:27