0

getDrawable is depreceated. How can I rewrite this code. I am unable to find the answer.

   public static List<Product> getCatalog(Resources res){
    if(catalog == null) {
        catalog = new Vector<Product>();
        catalog.add(new Product("Dead or Alive",src.getDrawable(R.drawable.deadoralive),
                "Dead or Alive by Tom Clancy with Grant Blackwood", 29.99));
        catalog.add(new Product("Switch", res
                .getDrawable(R.drawable.switchbook),
                "Switch by Chip Heath and Dan Heath", 24.99));
        catalog.add(new Product("Watchmen", res
                .getDrawable(R.drawable.watchmen),
                "Watchmen by Alan Moore and Dave Gibbons", 14.99));
    }

    return catalog;
}

What is the new best way to use it funcation.

vikky
  • 47
  • 8

2 Answers2

1

using ContextCompat.getDrawable. E.g.

  Drawable drawable = ContextCompat(context, R.drawable.deadoralive);
Blackbelt
  • 148,780
  • 26
  • 271
  • 285
0

From this thread, you must use

ContextCompat.getDrawable(context, R.drawable.***)
Community
  • 1
  • 1
ThomasThiebaud
  • 9,015
  • 4
  • 43
  • 66