title: How to create table with dynamic number of rows in Android
body: <p>I am trying to fill a TableLayout with a dynamic amount of rows based on an Array of icons, however i cannot get the rows to display on screen. The table should display a 5x3 grid of icons. The code I am using is below:</p>
  
  <pre><code>    Services serv = new Services();
  
      Item[] iconArray = serv.getIcons();
  
      TableLayout table = (TableLayout) findViewById(R.id.table1);
  
      int rowNum = iconArray.length/5;
      TableRow rows[]= new TableRow[rowNum];
  
      int count = 0;
      for (int i = 0; i &lt; iconArray.length; i++) { 
          final String name = iconArray[i].name; 
          final int icon = iconArray[i].icon;
  
          LayoutInflater inflater = LayoutInflater.from(MainActivity.this);
          View v = inflater.inflate(R.layout.icon, null,false);
          TextView text = (TextView) v.findViewById(R.id.text);
          text.setText(name);
  
          ImageView imageicon = (ImageView) v.findViewById(R.id.icon);
          imageicon.setOnClickListener(new OnClickListener() {
              public void onClick(View v) {
                  //Do some stuff
              }
          });
          Drawable drawicon = getResources().getDrawable(icon);
          imageicon.setBackgroundDrawable(drawicon);
  
          if(i == 4) //End of Row
          {   
              count++;
          }
          if(i == 9) //End of Row2
          {   
              count++;
          }
  
          rows[count] = new TableRow(this);
          rows[count].addView(v);
          table.addView(rows[count]);
      }
  </code></pre>
  
  <p>This does not output anything to the screen and the TableLayout remains empty. Can anyone tell me if I'm on the right lines?</p>
  
  <p>Any help would be appreciated.</p>
  
  <p>Thanks</p>