What is the scope of android:id?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/3719147/scope-of-r-id-values">Scope of R.id values</a>  </p>
</blockquote>



<p>Could someone please clarify the scope of resource id's in Android?    Recently I was making a custom title bar which contained a RelativeLayout called "header".   I was invoking this title bar in the <em>onCreate()</em> handlers of each of my Activities thusly:</p>

<pre><code>requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_layout);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);  
</code></pre>

<p>One of my Activities had a TextView in its layout with the id of "header" and in that Activity's <em>onCreate()</em> I do a  </p>

<pre><code>TextView tv1 = (TextView)findViewById(R.id.header); 
</code></pre>

<p>. . .  which blew up at runtime with ClassCastException, apparently because it thought I was trying to cast a RelativeLayout to a TextView.   Changing the name of the RelativeLayout in the title bar fixed it.</p>

<p>But I don't really understand this. Are Android resource id's global?     If so why wouldn't this collision be caught at build-time?</p>

<p>Note that this question has been asked before on SO: <a href="http://stackoverflow.com/questions/3719147/scope-of-r-id-values">Scope of R.id values</a>  . . .  Where the OP said "as far as I can tell" R.id's are global but my question is not a duplicate because neither of my questions is really addressed in that one.</p>
