title: Dynamic Span Adjustment for TextView In TableLayout
body: <p>Is there a way that I can set the span of a textview object in the java code, instead of having to do it in xml? I tried someone else's solution of using <strong>LayoutParams</strong>. I don't know if i didn't implement it correctly or if its just the wrong solution or maybe im just not realizing what my mistake in the code is, but it's causing the application to crash. Any help would be appreciated, im posting my code below.</p>
  
  <pre><code>package com.szymon.atrium;
  
  import java.util.ArrayList;
  import java.util.GregorianCalendar;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.widget.TableLayout;
  import android.widget.TableRow;
  import android.widget.TableRow.LayoutParams;
  
  
  public class TapeChart extends Activity
  {
  private ArrayList&lt;Room&gt; rooms;
  private ArrayList&lt;Arrival&gt; arrivals;
  private GregorianCalendar startDate = new GregorianCalendar(2011,1,1);
  private GregorianCalendar endDate = new GregorianCalendar(2011,1,10);
  private ArrivalGrid grid = new ArrivalGrid(arrivals, rooms, startDate.getTime(), endDate.getTime());
  
  private ArrayList&lt;ArrayList&lt;Cell&gt;&gt; displayArrival = grid.displayArrivalGrid();
  private ArrayList&lt;ArrayList&lt;Cell&gt;&gt; displayRooms = grid.displayRoomGrid();
  
  @Override
  public void onCreate(Bundle bundle)
  {
      super.onCreate(bundle);
      setContentView(R.layout.tape);
  
      TableLayout tbl = (TableLayout)findViewById(R.id.tapeChart);
  
      for(ArrayList&lt;Cell&gt; a : displayRooms)
      {
          TableRow newRow = new TableRow(this);
  
          for(Cell c : a)
          {
              LayoutParams param = new LayoutParams();
              param.span=c.getColSpan();
  
              MyTextView cell = new MyTextView(this);
              cell.setText(c.getContent());
              cell.setLayoutParams(param);
  
              newRow.addView(cell);
          }
  
          tbl.addView(newRow);
      }
  }
  
  public TableLayout getArrivalsTableLayout()
  {
  
      return null;
  }
  
  public void getRoomTableLayout()
  {
  
  
  }
  </code></pre>
  
  <p>}</p>