Xamarin pass data to activity from dynamically created button
<p>In my activity I am dynamically creating controls based off of sqlite data.  Each item will have a button with a click event that needs to send that rows ID to the new activity.</p>

<p>I have looked at the following page and can get this to work on a button that already exists in my layout.  But it doesn't seem to work when the button is dynamically created.  Is there something additional I need to do with the button for this to work?
<a href="https://developer.xamarin.com/recipes/android/fundamentals/activity/pass_data_between_activity/" rel="nofollow">https://developer.xamarin.com/recipes/android/fundamentals/activity/pass_data_between_activity/</a></p>

<p>Here is the code that creates the button dynamically:</p>

<pre><code>foreach (Tasks item in table)
{
    TableRow row = new TableRow(this);
    TextView txtTask = new TextView(this);
    txtTask.Text = item.Name;
    row.AddView(txtTask);
    tableLayout.AddView(row);
    row = new TableRow(this);
    Button btnEdit = new Button(this);
    btnEdit.Text = "Edit Record";
    btnEdit.SetWidth(300);
    btnEdit.Click += delegate 
    {
        Intent viewTask = new Intent(this, typeof(UpdateTaskActivity));
        viewTask.PutExtra("TaskId", item.Id);
        StartActivity(viewTask);
    };
    row.AddView(btnEdit);

    tableLayout.AddView(row);
}
</code></pre>

<p>In the OnCreate method of UpdateTaskActivity I have:</p>

<pre><code>string test = Intent.GetStringExtra("TaskId") ?? "error";
if (test != "error")
{
    //Do Stuff
}
</code></pre>

<p>But when I put a breakpoint down, my string is always null.  I did put a breakpoint to make sure the correct ID is being pulled.</p>

<p>Why does this work with a built in button but does not work with my dynamic one?  </p>

<p>Just to avoid confusion, in my startup screen I have a test button, and my main activity has the following code for that button. This code works fine, because the button isn't dymaically created:</p>

<pre><code>//Test button
Button btnTest = FindViewById&lt;Button&gt;(Resource.Id.btnTest);
btnTest.Click += delegate 
{
    var activity2 = new Intent(this, typeof(UpdateTaskActivity));
    activity2.PutExtra("TaskId", "1");
    StartActivity(activity2);
};
</code></pre>