title: Dynamically add rows to TableLayout
body: <p>I want to add rows to Table Layout by fetching contents from Database....I am trying below code but its not working.
  I created a class 'ProductDatabase' for the databse related work...and using the below code in another Activity...but its not showing any output</p>
  
  <pre><code>ProductDatabase pData; //Database Class
  TableLayout mainTable;
  Cursor cr;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.display_product_database);
  
      pData = new ProductDatabase(this);
      mainTable = (TableLayout) findViewById(R.id.mainTable);
  
  
  }
  
  @SuppressWarnings("deprecation")
  @Override
  protected void onResume() {
      super.onResume();
      pData.open();
      cr=pData.getDatabaseCursor(); //fetching cursor from Database Class
      int index=1;    
          for (cr.moveToFirst(); !cr.isAfterLast(); cr.moveToNext()) {
              TableRow tr=new TableRow(this);
                  tr.setId(1000+index);
                  tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
  
                  TextView labelName=new TextView(this);
                  labelName.setId(2000+index);
                  labelName.setText(cr.getString(cr.getColumnIndex(ProductDatabase.KEY_NAME)));
                  labelName.setTextColor(Color.BLACK);
                  labelName.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
                  tr.addView(labelName);
  
                  TextView labelBarcode=new TextView(this);
                  labelBarcode.setId(3000+index);
                  labelBarcode.setText(cr.getString(cr.getColumnIndex(ProductDatabase.KEY_BARCODE)));
                  labelBarcode.setTextColor(Color.BLUE);
                  labelBarcode.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
                  tr.addView(labelBarcode);
  
                  TextView labelCost=new TextView(this);
                  labelCost.setId(4000+index);
                  labelCost.setText(cr.getString(cr.getColumnIndex(ProductDatabase.KEY_COST)));
                  labelCost.setTextColor(Color.BLUE);
                  labelCost.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
                  tr.addView(labelCost);
  
                  mainTable.addView(tr, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
  
                  index++;
  
                              }
      pData.close();
  
  }
  </code></pre>
  
  <p>}</p>