Why is my custom view not appearing?
<p>When I comment out setContentView(boardView); in my Game.java my custom view in BoardView works fine and displays everything nicely... but onSizeChanged never gets called in BoardView.java... so I can't read the device width and height at runtime. If I leave setContentView uncommented onSizeChanged works... but the screen is blank!</p>

<p>I want to be able to read the screen width and height at runtime and set the sizes of my ImageViews at creation so they are the optimal size.</p>

<p>public class Game extends Activity implements OnClickListener{</p>

<p>private BoardView boardView;</p>

<pre><code>/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    boardView = new BoardView(this);

    setContentView(boardView);  // when this line disabled, it looks ok
    boardView.requestFocus();

}
</code></pre>

<p>public class BoardView extends View {
 private final Game game;
 private float width; // width of one unit
 private float height; // height of one unit</p>

<p>public BoardView(Context context){
  super(context);
  this.game = (Game)context;
  setFocusable(true);
  setFocusableInTouchMode(true);</p>

<pre><code>    LinearLayout maincontainer = new LinearLayout(game);
    maincontainer.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
    maincontainer.setGravity(Gravity.CENTER);
    maincontainer.setOrientation(LinearLayout.VERTICAL);   
    maincontainer.setBackgroundColor(Color.BLACK);

    LinearLayout innercontainer = new LinearLayout(game);
    innercontainer.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
    innercontainer.setGravity(Gravity.CENTER);
    innercontainer.setOrientation(LinearLayout.HORIZONTAL);   

    // declare a new table
    TableLayout layout = new TableLayout(game);
    layout.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); 

    // build a grid of ImageViews in a TableLayout
    for (int f=1; f&lt;=7; f++) {
        TableRow tr = new TableRow(game);
        for (int c=1; c&lt;=7; c++) {
         ImageView b = new ImageView(game);
         b.setImageResource(R.drawable.neworb);
         b.setOnClickListener(game);             
            tr.addView(b, 30,30);  // I'd like to not use fixed values here
        } // for
        layout.addView(tr);
    } // for
    innercontainer.addView(layout);
    maincontainer.addView(innercontainer);

    game.setContentView(maincontainer);
</code></pre>

<p>}</p>

<p>@Override
 protected void onSizeChanged(int w, int h, int oldw, int oldh){
  width = w/9f;
  height = width;</p>

<p>super.onSizeChanged(w, h, oldw, oldh);
 }</p>

<p>}</p>
