Reputation: 728
I have a string that identifies a resource that i want to grab.
I know about the following:
public int getIdentifier(String name, String defType, String defPackage)
However i need to use it in an external class, and it won't let me.
For example i have a string called "thefile" and i want to access R.raw.thefile
Any ideas? I'm stuck
Cheers
Upvotes: 2
Views: 681
Reputation: 48871
You could pass a Context to your external class. Example...
public Myclass {
public void doSomething (Context context) {
int resId = context.getResources().getIdentifier(...);
}
Then in your Activity...
MyClass myClass = new MyClass();
myClass.doSomething(this);
Upvotes: 5