Dynamically reference the R.raw.-content?

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Dynamically reference the R.raw.-content?

Postby Danneman » Mon Mar 30, 2009 12:27 pm

Is it possible to dynamically reference a specific resource in the R.raw.-folder?

For instance, if I have an mp3 in the raw-foler named "hello.mp3" I can reference it in the code with:

Code: Select all
mp = MediaPlayer.create(getBaseContext(), R.raw.hello);


But how do I replace the last "hello" with the content of a variable, so that I can load different mp3's from R.raw with the same code?

Code: Select all
// CODE NOT WORKING
String soundFile = "helloagain";
String mpPath = "R.raw." + soundFile;
mp = MediaPlayer.create(getBaseContext(), mpPath);
Danneman
Junior Developer
Junior Developer
 
Posts: 24
Joined: Thu Mar 26, 2009 12:42 pm

Top

Postby Emmanuel7 » Mon Mar 30, 2009 11:57 pm

I'm far from being a java specialist, but I would say reflexion can be used for this kind of feature.
Emmanuel7
Senior Developer
Senior Developer
 
Posts: 164
Joined: Fri Dec 12, 2008 2:17 am
Location: Paris

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 4 guests