Skip to content Skip to sidebar Skip to footer

Android: Creating Custom Class Of Resources

R class on android has it's limitations. You can't use the resources dynamically for loading audio, pictures or whatever. If you wan't for example, load a set of audio files for a

Solution 1:

I'm new to android and at least I didn't find how you could do that, depending on what objects are choosen or something more dynamic than that.

The Resources class has a getIdentifier() method that will give you the resource ID given the name as a string. This uses reflection, so you would want to cache the results, perhaps using a LinkedHashMap as an LRU cache.

Is it worth it?

IMHO, not really. I would just use getIdentifer() or directly use reflection myself. In fact, I have directly used reflection myself (with the LRU cache) to address this issue.

Post a Comment for "Android: Creating Custom Class Of Resources"