android setBackgroundColor in runtime and other general confusion help?
<p>i have a row of buttins created like this
i want to change the background colour at runtime in code.</p>

<pre><code>public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

LinearLayout track1 = (LinearLayout)findViewById(R.id.my_toggle_container); 

for (int i = 0; i&lt;32; i++) {
        ToggleButton tgl = new ToggleButton(this);
        tgl.setId(i);
    ...
track1.addView(tgl);
</code></pre>

<p>this names the id of the togglebuttons 1, 2, 3... (i presume?) 
i have an int variable called 'xBtn' that changes 1, 2,..
this is how i get a reference to the button using xBtn</p>

<pre><code>String buttonID = ""+xBtn;
            int resID = getResources().getIdentifier(buttonID, "id", "com.thing");
            //find the button
            ToggleButton tb = (ToggleButton) findViewById(resID);
            //change its colour
            tb.setBackgroundColor(Color.BLUE); 
</code></pre>

<p>it crashes on the setBackgroundColor line.</p>

<p>it may be obvious to someone whats wrong and thats what im hoping
any help would be totaly ace ta
thanks</p>

<p>main.xml</p>

<pre><code>&lt;LinearLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:id="@+id/my_toggle_container" android:orientation="vertical"&gt;
</code></pre>
