I need to do R.drawable."String name" Help!

Put your problem here if it does not fit any of the other categories.

I need to do R.drawable."String name" Help!

Postby arachnospore » Thu Mar 25, 2010 11:59 pm


I'm loading textures onto quads and I've got about 600+ textures to load. An xml file tells me what quads have what texture. I take the name of the texture and store it in a string called path. Can I have R.drawable.path?? Otherwise how the hell can I put in that amount of textures without having seperate loadTexrure methods or like 600 if statements.

Put on some golf shoes man or we'll never leave this place alive!
Junior Developer
Junior Developer
Posts: 11
Joined: Wed Nov 04, 2009 8:44 pm


Postby asolanki » Fri Mar 26, 2010 6:39 am


you can do one thing use map(key,value)

you can map string with int id.
like this

so that you can get int id by the string
Senior Developer
Senior Developer
Posts: 151
Joined: Thu Jan 08, 2009 7:32 am

Postby YaW » Fri Mar 26, 2010 10:38 am

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. int path = getResources().getIdentifier(nameOfTheDrawable, "drawable", "com.yourpackage.yourapp");
  3. Drawable drawFromPath = getResources().getDrawable(path);
Parsed in 0.013 seconds, using GeSHi

I guess this will do the trick ;)
Sorry for my poor English.
User avatar
Junior Developer
Junior Developer
Posts: 16
Joined: Thu Feb 25, 2010 8:54 am


Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 6 guests