title: How to Add Button to Custom View Programmatically?
body: <p>I'm a starter in Android Programming, and I'm developing a program by modifying some classes I found <a href="http://www.anddev.org/a_bouncing_ball_-_basic_graphics_animation_demo-t283.html" rel="nofollow">here.</a> So far I have the <code>DrawView</code> class as follows:</p>
  
  <pre><code>public class DrawView extends View {
     private Ball ball1;
  
     private Button kapabut;
  
      public DrawView(Context context) {
          super(context);
          setFocusable(true);
  
          ball1 = new Ball(context,R.drawable.ortatop);       
  
         kapabut=new Button(context);  //here, I cannot seem to add a button.
         kapabut.setVisibility(VISIBLE);
         kapabut.setText("xXx");
      }
  
      @Override protected void onDraw(Canvas canvas) {
          // move the balls at every canvas draw
          ball1.moveBall();
  
          //draw the balls on the canvas
          canvas.drawBitmap(ball1.getBitmap(), ball1.x, ball1.y, null);
          // refresh the canvas
          invalidate();
      }    
  }
  </code></pre>
  
  <p>The ball is created and moves, but I cannot seem to get the button "kapabut" anywhere. How can I make this button appear, and add an <code>onClick</code> method too?</p>
  
  <p>Any help would be appreciated, thanks.</p>
  
  <p>P.S.: I tried and added a Button using an XML layout, but now I want to make it with this class, and setting <code>setContentView(new DrawView(this));</code> in Main.java</p>