title: build layout at runtime android
body: <p>i have a complex xml layout which has list views..a row in the list view contains several text fields which are spaced evenly. i am using textview to store the text and then finally add all the items to the row...its working perfectly fine.
  but now i have case where in i am not sure, how many text fields i might get from a webservice. therefore i need to create the textview dynamically on run time, populate them and then insert into the list..
  is there anyway to declare,add and populate new textview fields on runtime?
  or is there is anyway to implement the spacing between the two fields?</p>
  
  <p>result of first call</p>
  
  <pre><code>__________________________
  |_____|_____|_____|______| 
  </code></pre>
  
  <p>result of second call</p>
  
  <pre><code>________________________________
  |_____|_____|_____|______|______|
  </code></pre>
  
  <p>I tried implementing the solution that was provided below (Kenny), but for some reason I am unable to add views into the list.. below is my code</p>
  
  <pre><code>public class HeaderAdapter extends ArrayAdapter&lt;Header&gt; {
  final Header[] listSymbols;
  private TextView textView;
  private LinearLayout row;
  
  public HeaderAdapter(Context context, int symResourceID,
          Header[] objects) {
      super(context, symResourceID, objects);
      listSymbols = objects;
  
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
      LayoutInflater inflater = (LayoutInflater) getContext()
      .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
      View row = inflater.inflate(R.layout.header_view, parent, false);
      Header headerRec = listSymbols[position];
      for(int i = 0 ; i &lt; listSymbols.length;i++){
          textView = new TextView(getContext());
          textView.setLayoutParams(new LayoutParams(
                  ViewGroup.LayoutParams.WRAP_CONTENT,  //Width of the view
                  ViewGroup.LayoutParams.WRAP_CONTENT));//Height of the view
          textView.setId(i);
              row.add??
  
          }
  }
  </code></pre>
  
  <p>The main activity that calls this</p>
  
  <pre><code>setContentView(R.layout.main);
  
      headerList.add(new Header("Symbol","Quantity","Price","Price Yesterday","52 Week High","52 Week Low","Change","Days Gain","Days Gain %","Returns"));
  
              Header[] tmpHeaderList = headerList.toArray(new Header[headerList.size()]);
  
              ArrayAdapter&lt;Header&gt; headerAdapter = new HeaderAdapter(this,R.layout.twoway_header_view,tmpHeaderList);
              headerListView.setAdapter(headerAdapter);
  </code></pre>
  
  <p>xml layout file..the main file</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent" android:layout_height="fill_parent"
      android:orientation="vertical"&gt;
  
      &lt;HorizontalScrollView android:layout_width="wrap_content"
          android:layout_height="wrap_content" android:scrollbars="none"
          android:id="@+id/headerHv"&gt;
  
          &lt;ListView android:id="@+id/header_listView1"
              android:layout_width="fill_parent" android:layout_height="wrap_content"
              android:background="@color/white" android:cacheColorHint="#00000000"
              android:smoothScrollbar="true" android:scrollbars="none" /&gt;
      &lt;/HorizontalScrollView&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>the file in which the template for the row is defined</p>
  
  <pre><code>    &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content" android:layout_height="wrap_content"
      android:orientation="horizontal"
      &gt;
      &lt;TextView android:id="@+id/headerList" android:layout_width="80dp"
          android:layout_height="wrap_content" android:textColor="#000000"
          android:typeface="sans" android:textStyle="normal"  /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>