title: Referring to programmatically created button and it's click event
body: <p>I'm absolute beginner when it comes to <em>mono for android</em>.</p>
  <p>I've used following code snippet to create 50 buttons programmatically:</p>
  <pre><code>for(int i=0;i&lt;50;i++)
              {
              //code to calculate x and y position
                  btn=new Button(this);
                  //btn.SetBackgroundColor(Android.Resource.Color.);
                  btn.SetTextSize(Android.Util.ComplexUnitType.Sp,8);
                  btn.Text=&quot;Scrip &quot;+i+&quot;\n&quot;+&quot;CMP &quot;+i+&quot;\n&quot;+&quot;%Chg &quot;+i;
                  lp = new RelativeLayout.LayoutParams(new ViewGroup.MarginLayoutParams((width+30)/5, (height-10)/10));
                  btn.LayoutParameters=lp;
                  lp.SetMargins(leftMargin,topMargin, 0, 0);
                  main.AddView(btn);
              }
              
              String str=&quot;&quot;;
              btn.Click += (sender, e) =&gt; 
              {
                  str=btn.Text;
                  Toast.MakeText(this, &quot;Selected=&quot;+str,ToastLength.Short).Show();
                  Console.WriteLine(&quot;Selected=&quot;+str);
              };
  </code></pre>
  <p>But <strong>one big problem</strong> with this code is at the end of the loop, <code>btn</code> object has reference of the last button <strong>only</strong>.</p>
  <p>So if any button other than last button is pressed, <code>button click</code> event is not fired.
  How to resolve it?
  Ideally, it should return the text of the clicked button.</p>
  <p>Also, referring to below screenshot, the default button style doesn't look good here. So I want to change it to exact rectangle and not rounded-rectangel(the default one).
  Any idea on this?</p>
  <p><em><strong>As I'm very new to this, any help will be appreciated !!</strong></em></p>
  <h2>EDIT</h2>
  <p>Asa result of your help, I'm able to create and refer all buttons appropriately.</p>
  <p><em><strong>But how to set their style as exact rectangle??</strong></em></p>
  <p><img src="https://i.imgur.com/EHUVq.png" alt="screen" /></p>