title: Android dynamic buttons - different amount in each row
body: <p>I am trying to add different number of buttons in each row. Say a random number of buttons in each row. The number of rows is a constant defined. I watched some tutorials and so far have the below code. This produces the same number of buttons in each row. Can you please help? Thank you.</p>
  
  <pre><code>private void populateButtons() { 
      TableLayout table = (TableLayout) findViewById(R.id.button); 
      for (int row = 0; row != NUM_ROWS; row++) { 
          TableRow tableRow = new TableRow(this); 
          tableRow.setLayoutParams(
                  new TableLayout.LayoutParams(
                          TableLayout.LayoutParams.MATCH_PARENT, 
                          TableLayout.LayoutParams.MATCH_PARENT, 1.0f));
          table.addView(tableRow);
          for (int col = 0; col != NUM_COLS; col++){ 
              final int FINAL_COL = col; 
              final int FINAL_ROW = row; 
              Button button = new Button(this); 
              button.setLayoutParams(
                      new TableRow.LayoutParams(
                              TableRow.LayoutParams.MATCH_PARENT, 
                              TableRow.LayoutParams.MATCH_PARENT, 1.0f)); 
              button.setBackgroundResource(R.drawable.button);
              tableRow.addView(button); 
              buttons[row][col] = button; 
          }
      }
  }
  </code></pre>