Listening to dynamically created toggle button in android
<p>Hello all I am implementing a control board with dynamically created toggle buttons where the number of toggle buttons is also dynamic, I am having a hard time appending a function to the dynamically created buttons, </p>

<pre><code> for (int i = 0; i &lt; len; i++) {
 ToggleButton tb[i] = new ToggleButton(this);
            LinearLayout.LayoutParams tbparams = new LinearLayout.LayoutParams
                    (90, LinearLayout.LayoutParams.WRAP_CONTENT);
            tbparams.setMargins(120, 0, 0, 0);
            tb[i].setBackgroundResource(R.drawable.bgtoggle);
            tb[i].setId(i+1);
            tb[i].setText("toggle_btn"+i+1);
            tb[i].setPadding(4, 4, 4, 4);
            tb[i].setLayoutParams(tbparams);
}
</code></pre>