tags:

views:

41

answers:

0

Because of the dynamic nature of our program, I have chosen to manually layout some of the screens/activities. I have a simple one here that has a title and 2 buttons, but the buttons never show on the screen.

Here is the code called from OnCreate that lays the screen out.

    public void buildScreen()
{
    myLayout = new LinearLayout (this);
    myLayout.setOrientation(LinearLayout.VERTICAL);
    myLayout.setLayoutParams (
        new LayoutParams (LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)
    );
    myLayout.setBackgroundColor(0x0000FF);

    txtTitle = new TextView (this);
    txtTitle.setText(myTitle);
    txtTitle.setLayoutParams (
        new LayoutParams (LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    txtTitle.setGravity (Gravity.CENTER);

    myLayout.addView(txtTitle);

    myActivate = new Button (this);
    myActivate.setText("Activate");
    myActivate.setBackgroundColor (Color.WHITE);
    myActivate.setTextColor (Color.BLACK);
    myActivate.setLayoutParams (
        new LayoutParams (0, 0));
    myActivate.setGravity (Gravity.CENTER);

    myLayout.addView(myActivate);

    myExit = new Button (this);
    myExit.setText("Exit");
    myExit.setBackgroundColor (Color.WHITE);
    myExit.setTextColor (Color.BLACK);
    myExit.setLayoutParams (
        new LayoutParams (0, 0));
    myExit.setGravity (Gravity.CENTER);

    myLayout.addView(myExit);

    setContentView (myLayout);
}

When this screen is displayed all I see is the title. For the life of me I cannot tell what could be wrong. Are buttons need some extra code to be called to make them visible? Note, I have tried various permutations of the Layout Parms on each button (i.e. 0, FILL_PARENT and WRAP_CONTENT) but none of those permutations makes a difference.

Any help would be appreciated.

Thank you

Julian