How to add checkboxes dynamically in android
<p>I need to create edittext fields dynamically in android. I have gone through the <a href="http://www.dreamincode.net/forums/topic/130521-android-part-iii-dynamic-layouts" rel="nofollow">link</a> and had written the button click action for it. That is when I click on the button the check boxes has to display. But when I am creating the checkbox object in the onclick action it is showing error.</p>

<p>Can someone please tell me why is it showing error? For this I will be thankful to you. </p>

<p>My code :</p>

<pre><code>public class InflationActivity extends Activity {

@Override

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ScrollView sv = new ScrollView(this);
    final LinearLayout ll = new LinearLayout(this);
    ll.setOrientation(LinearLayout.VERTICAL);
    sv.addView(ll);

    TextView tv = new TextView(this);
    tv.setText("Dynamic layouts ftw!");
    ll.addView(tv);

    EditText et = new EditText(this);
    et.setText("weeeeeeeeeee~!");
    ll.addView(et);

    Button b = new Button(this);
    b.setText("I don't do anything, but I was added dynamically. :)");
    ll.addView(b);



    b.setOnClickListener(new View.OnClickListener() {

     @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

        for(int i = 0; i &lt; 20; i++) {
         CheckBox ch = new CheckBox(this);
         ch.setText("I'm dynamic!");

            ll.addView(ch);
        }


        }
    });


    this.setContentView(sv);

   }
 }
</code></pre>
