Android: finding button by id
<p>I have a problem with finding buttons. I have an <code>AlertDialog</code> where I choose one of 5 options. When I choose an option I want change the color of the button I clicked. I declared buttons in xml file inside <code>&lt;RealativeLayout&gt;</code> but when I'm trying to find my button by id (id's are like "id1","id2"...)using the <code>findViewById</code> method, there is a mistake, which says that I can't use this method like I do:</p>

<pre><code>AlertDialog.Builder builder = new AlertDialog.Builder(StartGameActivity.this);

builder.setTitle(R.string.pickColor);
builder.setItems(R.array.colorArray, new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {
        Button btn_tmp;
        String theButtonId = "id";
        theButtonId = theButtonId+(String.valueOf(which));
        btn_tmp = (Button) findViewById(theButtonId);
    }
});
</code></pre>

<p>How can I fix that or maybe I should use other method?</p>

<p><strong>EDIT:</strong></p>

<p>I think I solved my problem. I used one of Button's method: getId() like this:</p>

<p><code>final int id = clickedButton.getId();</p>

<p>final ImageButton btn_tmp;
btn_tmp = (ImageButton)findViewById(id);</code></p>
