title: Create ImageView programmatically without Layout
body: <p>I'm trying to create an ImageView in code, setting the image resource and then add the ImageView as a child-view to my main view. All examples I found used a layout for that. But inside the constructor of my view I can't figure out how to do that.</p>
  
  <p>Here are the code snippets:</p>
  
  <pre><code>public class MainActivity extends Activity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(new CanvasView(this));
  
      }
  }
  </code></pre>
  
  <p>The view:</p>
  
  <pre><code>public class CanvasView extends SurfaceView implements SurfaceHolder.Callback {
      public CanvasView(Context context) {
          super(context);
  
          SurfaceHolder sh = getHolder();
          sh.addCallback(this);
  
          ImageView iv = new ImageView(context);
          iv.setImageResource(R.drawable.wand);
  
          // how to add iv to myself?
      }
  }
  </code></pre>