Android: Creating custom class of resources
<p>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 choosen object you can't do something like:</p>

<pre><code>R.raw."string-upon-choosen-object"
</code></pre>

<p>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. So, I thought about making it dynamic with a little of memory overhead. But, I'm in doubt if it's worth it or just working different with external resources.</p>

<h2>The idea is this:</h2>

<p>Modify the ant build xml to execute my own task. This task, is a java program that parses the R.java file building a set of HashMaps with it's  pair (key, value). I have done this manually and It's working good. So I need some experts voice about it. </p>

<p>This is how I will manage the whole thing:</p>

<p>Generate a base <code>Application</code> class, e.g. <code>MainApplicationResources</code> that builds up all the require methods and attributes. Then, you can access those methods invoking <code>getApplication()</code> and then the desired method. </p>

<p>Something like this:</p>

<pre><code>  package [packageName]

  import android.app.Application;

  import java.util.HashMap;

  public class MainActivityResources extends Application {

      private HashMap&lt;String,Integer&gt; [resNameObj1];
      private HashMap&lt;String,Integer&gt; [resNameObj2];
      ...
      private HashMap&lt;String,Integer&gt; [resNameObjN];

      public MainActivityResources() {
          super();

      [resNameObj1] = new HashMap&lt;String,Integer&gt;();
      [resNameObj1].put("[resNameObj1_Key1]", new Integer([resNameObj1_Value1]));
      [resNameObj1].put("[resNameObj1_Key2]", new Integer([resNameObj1_Value2]));

      [resNameObj2] = new HashMap&lt;String,Integer&gt;();
      [resNameObj2].put("[resNameObj2_Key1]", new Integer([resNameObj2_Value1]));
      [resNameObj2].put("[resNameObj2_Key2]", new Integer([resNameObj2_Value2]));
      ...
      [resNameObjN] = new HashMap&lt;String,Integer&gt;();
      [resNameObjN].put("[resNameObjN_Key1]", new Integer([resNameObjN_Value1]));
      [resNameObjN].put("[resNameObjN_Key2]", new Integer([resNameObjN_Value2]));
      }

      public int get[ResNameObj1](String resourceName) {
          return [resNameObj1].get(resourceName).intValue();
      }

      public int get[ResNameObj2](String resourceName) {
          return [resNameObj2].get(resourceName).intValue();
      }

      ...

      public int get[ResNameObjN](String resourceName) {
          return [resNameObjN].get(resourceName).intValue();
      }
}
</code></pre>

<h2>The question is:</h2>

<p>Will I add too much memory use of the device? Is it worth it?</p>

<p>Regards,</p>
