title: Android Runtime Layout Tutorial
body: <p>Does anyone know how to perform or have a good reference for doing an activity layout at runtime in android?</p>
  
  <p>Here is the code for my activity. I'm sure I'm just neglecting to do something here:</p>
  
  <pre><code>package com.isi.sa;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.widget.LinearLayout;
  import android.widget.TextView;
  
  public class SimpleAssessmentTest extends Activity {
    LinearLayout layout;
    TextView question;
  
    @Override
    public void onCreate(Bundle icicle) {
      super.onCreate(icicle);
  
      layout = new LinearLayout(this);
      question = new TextView(this);
  
      layout.setLayoutParams(new ViewGroup.LayoutParams(-1,-1));
      layout.setBackgroundColor(R.color.blue);
  
      question.setLayoutParams(new ViewGroup.LayoutParams(-1,-2));
      question.setTextColor(R.color.green);
      question.setTextSize(1,14);
  
      question.setText("This is question1");
      layout.addView(question);
  
      setContentView(layout);
    }
  }
  </code></pre>
  
  <p>As you can see I'm just trying to add a linear layout with a single text view (just for testing purposes) however, when the activity starts I just get a black screen with a title bar of my app name.</p>
  
  <p>Thanks</p>