views:

192

answers:

1

for example:

public final class R {

    public static final class raw {
        public static final int yuri=0x7f040000;
    }
}

How can I get the resource by its name? Without using R.raw.yuri = (int)

+3  A: 
getResources().getIdentifier( "yuri" , "raw" , this.class.getPackageName() );

I found this to be extremely slow. I stripped it out of my whole project after doing some profiling and used int[] instead.

drawnonward
That's because this uses reflection. The performance really should only matter in a loop or something, and then you can cache the lookup.
CommonsWare
Yes, we had what amounts to a bitmap font with one resource per letter and switching to an int[] of known constants was perceptibly faster.
drawnonward