title: How does the mapping between android resources and resources ID work?
body: <p>It is magical for Android to locate the proper resource just through the <strong><em>R.id.XXX</em></strong>. </p>
  
  <p>AFAIK, the resources are compiled to binary format, so how does this mapping logic work under the hood?</p>
  
  <p><strong>Maybe</strong> it works like this:</p>
  
  <p>For e.g., in the <strong>layout1.xml</strong>, we got:</p>
  
  <pre><code>&lt;Button android:id="@+id/button1" &gt;
  </code></pre>
  
  <p>and AAPT will generate this in the R.java:</p>
  
  <pre><code>public static final int button1=0x7f05000b;
  </code></pre>
  
  <p>When the <strong>*.apk</strong> is genrated, the <strong>@+id/button1</strong> with be substituded with "0x7f05000b".</p>
  
  <p>Thus, when we call:</p>
  
  <pre><code>findViewById(R.id.button1);
  </code></pre>
  
  <p>we are essentially still do the search based on the ID, though the ID is a number like 0x7f05000b.</p>
  
  <p>Thanks!</p>
  
  <h2>ADD</h2>
  
  <p><strong>What I really want to know, is how the resource id integer is parsed into the resource content? In other words, how does the Android runtime locate the resource content with resource id as the sole clue?</strong></p>
  
  <p>For example, how is a drawable picture found with a resource id? Or how is a string value is found with a resource id?</p>