I've tried this:
r = Resources.getSystem().getIdentifier("ball_red","drawable","com.Juggle2");
Log.i("FindBall","R = "+r);
And this:
r = Resources.getSystem().getIdentifier("com.Juggle2:drawable/ball_red", null, null);
But 'r' always ends up as zero.
I'm calling this line from inside a helper class that's not an Activity and doesn't extend anything, so I can't simply call getResources()
, but I can pass it from my SurfaceView
.
Eventually, I want to replace "ball_red"
with a variable, but first thing's first. This isn't working.
com.Juggle2
is indeed my package name. drawable
is the res
folder that it's in, and, the name of the file is indeed ball_red
.
R.java says:
public static final int ball_red=0x7f020027;
So I'm not sure why it isn't working.
So I can't use Resources, I must pass a context, and I'm doing that this way: Inside here:
class Collection extends SurfaceView implements SurfaceHolder.Callback {
I'm making a new instance of my class and passing it getContext()
as a parameter.
Resources.getSystem()
: "Return a global shared Resources object that provides access to only system resources (no application resources), and is not configured for the current screen (can not use dimension units, does not change based on orientation, etc)." As answered by @Sajmon, you'll need to pass in aContext
instance to your (static) helper method to access application-specific resources. – Egret