1

I need to get a resource from a String:

What i do:

InputStream is = ctx.getResources().openRawResource(R.drawable.image1); 

What i need:

InputStream is = ctx.getResources().openRawResource(getDrawable("image1")); 

Anyone knows how to implement getDrawable() funcion?

Thanks!

0

1 Answer 1

1

use getResources().getIdentifier for getting drawable id using string name as :

int drwableid = ctx.getResources().getIdentifier("image1", "drawable", ctx.getPackageName()); InputStream is = ctx.getResources().openRawResource(drwableid); 
Sign up to request clarification or add additional context in comments.

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.