I want to dynamically create button to pass id
<pre><code>for(int i=0;i&lt;n;i++)
        {
        Button btn = new Button(this); 
        btn.setLayoutParams(new LinearLayout.LayoutParams(150, 45));
        btn.setId(i);
        linearLayout.addView(btn); 
        try {
           btn.setOnClickListener(new OnClickListener() {

                public void onClick(View v){
                    Intent userTry = new Intent(Ed.this,Op.class);
                    startActivity(userTry);
                }
            });
        } catch (ActivityNotFoundException anfe) {
            Log.e("onCreate", "Activity Not Found", anfe);
        }
</code></pre>

<p>Android : I want to dynamically create button such that it passes it id to the next activity it goes to. But i am getting an error. Thanks for the help</p>
