title: Android - Adding custom surfaceView to xml defined surfaceView not working
body: <p>I am trying to add a custom surfaceView class to a surfaceView that has been declared in a xml layout. The problem is that I cannot get the custom class add the the xml defined surfaceView. Some how it just does not start.</p>
  
  <p>This is my code:<br>
  <b>MainActivity</b></p>
  
  <pre><code>@Override
  public void onCreate(Bundle savedInstanceState)
  {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      sineWaveSurfaceView = (SineWaveSurfaceView) findViewById(R.id.surfaceView);
  }
  </code></pre>
  
  <p><b>MainActivity Layout</b></p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context=".MainActivity" &gt;
  
      &lt;mark.dijkema.android.eindopdracht.SineWaveSurfaceView
          android:id="@+id/surfaceView"
          android:layout_width="fill_parent"
          android:layout_height="100dp"
          android:layout_marginTop="20dp" /&gt;
  
      &lt;ListView
          android:id="@+id/song_list"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_marginTop="20dp" &gt;
      &lt;/ListView&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><b>SineWaveSurfaceView Class</b></p>
  
  <pre><code>public class SineWaveSurfaceView extends SurfaceView implements SurfaceHolder.Callback
  {
  private Context context;
  
  public SineWaveSurfaceView(Context context)
  {
      super(context);
      // TODO Auto-generated constructor stub
  
      this.context = context;
      getHolder().addCallback(this);
  
      Log.e("constructor", "done");
  }
  
  public SineWaveSurfaceView(Context context, AttributeSet attrs)
  {
      super(context, attrs);
      // TODO Auto-generated constructor stub
  }
  
  public SineWaveSurfaceView(Context context, AttributeSet attrs, int defStyle)
  {
      super(context, attrs, defStyle);
      // TODO Auto-generated constructor stub
  }
  
  protected void OnDraw(Canvas canvas, int value)
  {
      //canvas.drawColor(Color.WHITE);
  
      Paint paint = new Paint();
      paint.setColor(Color.WHITE);
  
      float y = Float.valueOf(String.valueOf(value)); 
  
      for(float x = 0; x &lt; 200; x += 0.1f)
      {
          canvas.drawPoint(x, y, paint);
      }
  }
  
  @Override
  public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3)
  {
      // TODO Auto-generated method stub
  
  }
  
  @Override
  public void surfaceCreated(SurfaceHolder arg0)
  {
      // TODO Auto-generated method stub
  
      Log.e("start", "started");
  }
  
  @Override
  public void surfaceDestroyed(SurfaceHolder arg0)
  {
      // TODO Auto-generated method stub
  
  }
  
  }
  </code></pre>
  
  <p>The problem is that the Log.e("constructor", "done"); in the constructor of the SineWaveSurfaceView is not even showing up.</p>
  
  <p>What am I doing wrong, because when I do something like</p>
  
  <pre><code>sineWaveSurfaceView = new sineWaveSurfaceView(this);
  </code></pre>
  
  <p>then it works, but it is not attached to the surfaceView defined in the xml layout.</p>