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.

2
  • 1
    Its a duplicate question Commented Nov 9, 2015 at 9:43
  • I know a lot of question had been asked about geDrawable on this site But I am new to Android Development so I needed exact answer as I was unable to do so. Commented Nov 12, 2015 at 16:34

2 Answers 2

1

using ContextCompat.getDrawable. E.g.

 Drawable drawable = ContextCompat(context, R.drawable.deadoralive); 
Sign up to request clarification or add additional context in comments.

Comments

0

From this thread, you must use

ContextCompat.getDrawable(context, R.drawable.***) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.