title: Android: Get Resource ID of custom xml class object by name
body: <p>I have a custom folder, file and custom XML resource class in my "res" folder.</p>
  
  <p>I create some custom objects, which I call:</p>
  
  <pre><code>&lt;area id="@+id/someId" name="Some Name" /&gt;
  </code></pre>
  
  <p>I can access them statically by R.id.someId.</p>
  
  <p>However, I need to get the resource id at runtime and I need to do that by the "name". In other words, I display that "Some Name" in the list and I need to get the id of  knowing that the user selected "Some Name" from the ListView. (I am <strong>NOT</strong> looking for the id of the ListItem, I actually want to search my resources and get the id of the area xml object)</p>
  
  <p>For example:</p>
  
  <p>I would like to do something of the following:</p>
  
  <pre><code>int id = getIdFromResourceName("Some Name"); 
  </code></pre>
  
  <p>Is this possible?</p>
  
  <p>I have tried using:</p>
  
  <pre><code>int i = this.getResources().getIdentifier("Some Name", "area", this.getPackageName());
  </code></pre>
  
  <p>...but that did not seem to work. I always get 0.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>As suggested below by Geobits, is there a way to load all of the resources from a res file and save them in an array/map, such as <code>Map&lt;id,name&gt;</code> so I can search them later?</p>
  
  <p>Thank you for the help!</p>