title: How to add view components dynamically from activity
body: <p>I am attempting to create a user interface dynamically. I have successfully create a view and loaded my background image. I have created two additional small view items to display on the background. My problem is that I have not been able to find any advice/instruction that tells me how to draw the small views. It seems that it should be a trivial exercise and I am guessing it is just finding the correct referencing. Hope someone out there can point me in the right direction.</p>
  
  <p>Here is my Activity:</p>
  
  <pre><code>public class GhostActivity extends Activity implements OnTouchListener
  {
  private DrawView ghostView;
  public Card mCard1, mCard2;
  
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      // ToDo add your GUI initialization code here        
      super.onCreate(savedInstanceState);
      // requesting to turn the title OFF
      requestWindowFeature(Window.FEATURE_NO_TITLE);
      // making it full screen
      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  WindowManager.LayoutParams.FLAG_FULLSCREEN);
      ghostView = new DrawView(this);
      setContentView(ghostView);
  
      //get the window size
      Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
  
      Context context = getApplicationContext();
      //create view items with initial positions
      Point startPoint;
      startPoint = new Point();
      startPoint.x = 5;
      startPoint.y = 3;
      mCard1 = new Card(context, 1, R.drawable.bol_geel, startPoint);
      startPoint.x = 5;
      startPoint.y = 43;
      mCard2 = new Card(context, 2, R.drawable.bol_rood, startPoint);
  
      //now display them on the ghostView *****************HOW?
  
      // set the callbacks
      ghostView.setOnTouchListener(this);
      mCard1.setOnTouchListener(this);
      mCard2.setOnTouchListener(this);
  
      }
  </code></pre>
  
  <p>and here is the View;</p>
  
  <pre><code>public class DrawView extends View 
  {
  Drawable bg ; 
  public DrawView(Context context) {
     super(context);
     //setFocusable(true); 
     Drawable bg = this.getResources().getDrawable(R.drawable.bubbleblue480x800);
     setBackgroundDrawable(bg);
     }
  
  
  @Override protected void onDraw(Canvas canvas) {
  //   canvas.drawColor(0x0000000);     //if you want another background color       
  
      //draw  on the canvas
    }
  }
  </code></pre>
  
  <p>edit: I believe my problem is needing to pass a pointer to the ghostView canvas. what makes me think that is if I create the children within ghostView then call their .draw method they appear exactly as I would expect.</p>
  
  <pre><code>@Override protected void onDraw(Canvas canvas) {
      canvas.drawColor(0x0000000);     //if you want another background color       
  
      //draw the cards on the canvas
      mCard1.draw(canvas);
      mCard2.draw(canvas);
  }
  </code></pre>
  
  <p>so at this point I am wondering how to get a reference pointer to the ghostView canvas.
  To be honest I am finding the whole Activity - View relationship confusing.</p>
  
  <p>Edit: I have taken a different approach based on detail in this tutorial
  <a href="http://www.kellbot.com/2009/06/android-hello-circle/" rel="nofollow">http://www.kellbot.com/2009/06/android-hello-circle/</a>
  It uses a FrameLayout and it seems I can achieve my objective.</p>