Android Runtime Layout Tutorial

Posted by Ryan on Stack Overflow See other posts from Stack Overflow or by Ryan
Published on 2010-04-22T19:16:52Z Indexed on 2010/04/22 19:33 UTC
Read the original article Hit count: 535

Filed under:
|
|

Does anyone know how to perform or have a good reference for doing an activity layout at runtime in android?

Here is the code for my activity. I'm sure I'm just neglecting to do something here:

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.setBackgroundColor(R.color.black);
    question.setTextColor(R.color.white);        

    question.setText("This is question1");
    layout.addView(question);
  }
}

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.

Thanks

© Stack Overflow or respective owner

Related posts about android

Related posts about android-layout