title: How to assign different values to two different table without writing almost same code for other table?
body: <p>I want to create two tables which have different headers in first row. both tables have 4 columns in header row. How can i create two table with different header values without writing this same code twice?</p>
  
  <pre><code>public void addHeaders(TableLayout t) {
  
      /* Create a TableRow dynamically */
      TableRow tr = new TableRow(this);
      tr.setBackgroundColor(GRAY);
      tr.setLayoutParams(new TableLayout.LayoutParams(
              TableLayout.LayoutParams.MATCH_PARENT,
              TableLayout.LayoutParams.WRAP_CONTENT));
  
  
      /* Creating a TextView to add to the row */
      TextView addressTV = new TextView(this);
      addressTV.setText("Address");
      addressTV.setTextColor(Color.BLACK);
      addressTV.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
      addressTV.setGravity(Gravity.CENTER_HORIZONTAL);
      addressTV.setPadding(0, 7, 0, 7);
      addressTV.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1.7f));
      tr.addView(addressTV);  // Adding textView to tablerow.
  
      /* Creating a TextView to add to the row */
      TextView typeTV = new TextView(this);
      typeTV.setText("Type");
      typeTV.setTextColor(Color.BLACK);
      typeTV.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
      typeTV.setGravity(Gravity.CENTER_HORIZONTAL);
      typeTV.setPadding(0, 7, 0, 7);
      typeTV.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f));
      tr.addView(typeTV);  // Adding textView to tablerow.
  
      /* Creating another textview */
      TextView amountTV = new TextView(this);
      amountTV.setText("Amount");
      amountTV.setTextColor(Color.BLACK);
      amountTV.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
      amountTV.setGravity(Gravity.CENTER_HORIZONTAL);
      amountTV.setPadding(0, 7, 0, 7);
      amountTV.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1.2f));
      tr.addView(amountTV); // Adding textView to tablerow.
  
      /* Creating another textview */
      TextView dateTV = new TextView(this);
      dateTV.setText("Date");
      dateTV.setTextColor(Color.BLACK);
      dateTV.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
      dateTV.setGravity(Gravity.CENTER_HORIZONTAL);
      dateTV.setPadding(0, 7, 0, 7);
      dateTV.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1.5f));
      tr.addView(dateTV); // Adding textView to tablerow.
  
      // Add the TableRow to the TableLayout
      tl.addView(tr, new TableLayout.LayoutParams(
              LayoutParams.MATCH_PARENT,
              LayoutParams.WRAP_CONTENT));
  
  }
  </code></pre>