Dynamic views with one static xml
<p>I have an xml file right now which has a TableLayout within a LinearLayout.  Within the TableLayout are TableRows with Buttons.  Within my Java code, I do a setOnClickListener for each button.</p>

<p>The problem is I have several xml files like this which are exactly the same, except within the xml the ID and text's of the different buttons are different.  </p>

<p>So one file it will be </p>

<pre><code>&lt;Button android:id="@+id/one" android:text="one" /&gt; 
&lt;Button android:id="@+id/two" android:text="two" /&gt; 
</code></pre>

<p>and another file it will be </p>

<pre><code>&lt;Button android:id="@+id/three" android:text="three" /&gt;
&lt;Button android:id="@+id/four" android:text="four" /&gt;
</code></pre>

<p>In Java, in one part of a switch/case statement I have a case that is:</p>

<pre><code>setContentView(R.layout.a);
Button bOne = (Button) findViewById(R.id.one);
Button bTwo = (Button) findViewById(R.id.two);
</code></pre>

<p>and another I have:</p>

<pre><code>setContentView(R.layout.b);
Button bThree = (Button) findViewById(R.id.three);
Button bFour = (Button) findViewById(R.id.four);
</code></pre>

<p>The redundancy goes out to more than two xml files, this is just an example.</p>

<p>Is there any way to do this and not have multiple layout files, but to do this all in one layout file?  The xml files are all exactly the same, but for the id and text portions of the buttons.</p>

<p>I really don't care how this is done - in Java, in xml, or however.  It's just that I make minor tweaks to the layout once in a while, and don't want to have to continue to tweaking every file with exactly the same layout but for the button id's and texts.  I'd like to tweak the layout once and have it work across all of them when I change the layout.  If I have to put the entire layout file in Java, that would be fine.</p>
