title: Layout for a League table
body: <p>I'm having some issue creating a layout for a league table. In my current layout, i have created a table with consists of two rows. The first row has the headings i want, and the second row has black fields that consist of the data that is obtained. I get the data from my server which contains an xml file. The problem i am having is not getting the data as i can do that.. The problem is that when i display the data i use a ListAdapter which need a layout linked to it. But when i link the appropriate layout, i get a repeat of header after every line... e.g. </p>
  
  <p>TEAM           P  W   L  D  P</p>
  
  <p>Arsenal        1  1   1  1  1</p>
  
  <p>TEAM           P  W   L  D  P</p>
  
  <p>Aston Villa    1  1   1  1  1</p>
  
  <p>I'm sure its a simple error to fix.... maybe i have to you something else to display the data???</p>
  
  <p><strong>Below is the code for the main</strong></p>
  
  <pre><code>public class tab_1 extends ListActivity {
  
      public int a = Football_appActivity.league;
  
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.listplaceholder);
  
          ArrayList&lt;HashMap&lt;String, String&gt;&gt; mylist = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
          if(a==1){
              String xml = XMLfunctions.getXML_prem_table();
              Document doc = XMLfunctions.XMLfromString(xml);
              int numResults = XMLfunctions.numResults(doc);
  
              if((numResults &lt;= 0)){
                  Toast.makeText(tab_1.this, "League Table", Toast.LENGTH_LONG).show();
                  finish();
              }
  
              NodeList nodes = doc.getElementsByTagName("team");
  
              for (int i = 0; i &lt; nodes.getLength(); i++) {
                  HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
  
                  Element e = (Element)nodes.item(i);
                  map.put("id", XMLfunctions.getValue(e, "id"));
                  map.put("name", "" + XMLfunctions.getValue(e, "name"));
                  map.put("played", "" + XMLfunctions.getValue(e, "played"));
                  map.put("won", "" + XMLfunctions.getValue(e, "won"));
                  map.put("drawn", "" + XMLfunctions.getValue(e, "drawn"));
                  map.put("lost", "" + XMLfunctions.getValue(e, "lost"));
                  map.put("points", "" + XMLfunctions.getValue(e, "points"));
                  mylist.add(map);
              }
              **
              ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.main_tab,
                  new String[] { "name", "played", "won", "drawn", "lost", "points"},
                  new int[] { R.id.item_title, R.id.item_played, R.id.item_won,
                  R.id.item_drawn, R.id.item_lost, R.id.item_points});**
  
              setListAdapter(adapter);
  
              final ListView lv = getListView();
              lv.setTextFilterEnabled(true);
              lv.setOnItemClickListener(new OnItemClickListener() {
                  public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                      @SuppressWarnings("unchecked")
                      HashMap&lt;String, String&gt; o = (HashMap&lt;String, String&gt;) lv.getItemAtPosition(position);
                      Toast.makeText(tab_1.this, o.get("name") + " have Won '" + o.get("won") + "' games, and are currently on '" + o.get("points") + "' points!", Toast.LENGTH_LONG).show();
                  }
              });
          }
  </code></pre>
  
  <p><strong>Below is the layout called main_tab.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:padding="7dp"
  &gt;
  &lt;TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:stretchColumns="1"
  android:id="@+id/table123"&gt;
  &lt;TableRow&gt;
  &lt;TextView 
      android:text="Name"
      android:id="@+id/team_title"&gt;
      &lt;/TextView&gt;
  &lt;TextView android:text="P "
      android:gravity="right"
      android:id="@+id/team_played"&gt;
  &lt;/TextView&gt;
  &lt;TextView android:text="W"
      android:id="@+id/team_won"&gt;
  &lt;/TextView&gt;
  &lt;TextView android:text="D"
      android:id="@+id/team_drawn"&gt;
  &lt;/TextView&gt;
  &lt;TextView android:text="L"
      android:id="@+id/team_lost"&gt;
  &lt;/TextView&gt;
  &lt;TextView android:text="P"
      android:id="@+id/team_points"&gt;
  &lt;/TextView&gt;
  &lt;/TableRow&gt;
  
  &lt;TableRow&gt;
      &lt;TextView  
          android:id="@+id/item_title"
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content" 
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:padding="2dp"
          android:textSize="20dp" /&gt;
          &lt;TextView  
          android:id="@+id/item_played"
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content"
          android:gravity="right" 
          android:padding="2dp"
          android:textSize="13dp" /&gt;
          &lt;TextView  
          android:id="@+id/item_won"
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content"
          android:padding="2dp"
          android:textSize="13dp" /&gt;
          &lt;TextView  
          android:id="@+id/item_drawn"
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content"
          android:padding="2dp"
          android:textSize="13dp" /&gt;
          &lt;TextView  
          android:id="@+id/item_lost"
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content"
          android:padding="2dp"
          android:textSize="13dp" /&gt;
          &lt;TextView  
          android:id="@+id/item_points"
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content"
          android:padding="2dp"
          android:textSize="13dp" /&gt;
          &lt;/TableRow&gt;
          &lt;/TableLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>Below is the loyout for ListPlaceHolder.XML</strong></p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="horizontal"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"&gt;    
  
  &lt;ListView
      android:id="@id/android:list"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_weight="1"
      android:drawSelectorOnTop="false" /&gt;
  
  &lt;TextView
      android:id="@id/android:empty"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="No data"&gt;
      &lt;/TextView&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <hr>
  
  <p>Ok cool.. so i have changed the layout of the main_tab.xml and created a new layout called table_header.xml That contains the headings for the league e.g. Name, Played, Won, Lost etc... But now i have an error in the logcat.. Below is the code what for main page...</p>
  
  <pre><code>if(a==1){
              String xml = XMLfunctions.getXML_prem_table();
              Document doc = XMLfunctions.XMLfromString(xml);
               int numResults = XMLfunctions.numResults(doc);
  
               if((numResults &lt;= 0)){
                  Toast.makeText(tab_1.this, "League Table", Toast.LENGTH_LONG).show();  
                  finish();
               }
  
              NodeList nodes = doc.getElementsByTagName("team");
  
              setContentView(R.layout.table_header);
  
              for (int i = 0; i &lt; nodes.getLength(); i++) {                           
                  HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();    
  
                  Element e = (Element)nodes.item(i);
                  map.put("id", XMLfunctions.getValue(e, "id"));
                  map.put("name", "" + XMLfunctions.getValue(e, "name"));
                  map.put("played", "" + XMLfunctions.getValue(e, "played"));
                  map.put("won", "" + XMLfunctions.getValue(e, "won"));
                  map.put("drawn", "" + XMLfunctions.getValue(e, "drawn"));
                  map.put("lost", "" + XMLfunctions.getValue(e, "lost"));
                  map.put("points", "" + XMLfunctions.getValue(e, "points"));
                  mylist.add(map);            
              }       
  
               ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.main_tab, 
                               new String[] { "name", "played", "won", "drawn", "lost", "points"}, 
                               new int[] { R.id.item_title, R.id.item_played, R.id.item_won,
                                          R.id.item_drawn, R.id.item_lost, R.id.item_points});
  
               setListAdapter(adapter);
  
               final ListView lv = getListView();
               lv.setTextFilterEnabled(true); 
               lv.setOnItemClickListener(new OnItemClickListener() {
                  public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {              
                      @SuppressWarnings("unchecked")
                      HashMap&lt;String, String&gt; o = (HashMap&lt;String, String&gt;) lv.getItemAtPosition(position);                   
                      Toast.makeText(tab_1.this, o.get("name") + " have Won '" + o.get("won") + "' games, and are currently on '" + o.get("points") + "' points!", Toast.LENGTH_LONG).show(); 
  
                  }
              });
  </code></pre>
  
  <p>The line for changing the layout i have used is:
  setContentView(R.layout.table_header);</p>
  
  <p>is this correct????</p>
  
  <p>The first error i get is (there is a long list, but i think this is the cause):</p>
  
  <p>04-15 09:46:42.268: E/AndroidRuntime(346): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.julian.football_app/com.julian.football_app.tab_1}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'</p>