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

Hi,

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.

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

Top

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

Hi!!

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

you can map string with int id.
like this
map("path1",R.id.path1)

so that you can get int id by the string
asolanki
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");
  2.  
  3. Drawable drawFromPath = getResources().getDrawable(path);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


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

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot] and 31 guests