title: Android: How to programmatically add button to view
body: <p>In my Android activity, I create a custom view that extends SurfaceView (using MonoDroid so slight variations in syntax):</p>
  
  <pre><code>class FriendsView : SurfaceView
  {
      ...
  
      public FriendsView(Context context) : base(context)
      {
  
          ... create my custom view ...
  
      }
  
  
  }
  </code></pre>
  
  <p>In my Activity class, I set the content view to the view:</p>
  
  <pre><code>protected override void OnCreate(Bundle bundle)
  {
  
      base.OnCreate(bundle);
  
      ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.FillParent);
  
      FriendsView friendsView = new FriendsView(this);
  
      SetContentView(friendsView, layoutParams);
  
  }
  </code></pre>
  
  <p>I want to add a button to the view, but cannot work out how to do this. Everything I have read starts from the point of view of the main.xml, but I don't see how to use this to declare a button which is visible in my view. Equally, I cannot find a method in either Activity or View classes which lets me add a Button object programatically.</p>
  
  <p>I feel sure I am missing something conceptually, but would welcome any help to get me going in the right direction.</p>