0

I am trying to make a league table which has a fixed header... I posted previously and got advice, but i am still having some issues! I'm sure it is only a minor issue that is causing me my problems!!!

Below is the code for the main page:

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<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();

        if(a==1){
            String xml = XMLfunctions.getXML_prem_table();
            Document doc = XMLfunctions.XMLfromString(xml);
            int numResults = XMLfunctions.numResults(doc);

            if((numResults <= 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 < nodes.getLength(); i++) {
                HashMap<String, String> map = new HashMap<String, String>();

                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<?> parent, View view, int position, long id) {
                    @SuppressWarnings("unchecked")
                    HashMap<String, String> o = (HashMap<String, String>) 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(); 
                }
            });
        }

The line that is causing me all the error is the line where I call a different layout:

setContentView(R.layout.table_header);

I'm assuming that I am not call it properly.. is this a correct assumption????

Below are the layouts:

listplaceholder.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">    

    <ListView
        android:id="@id/android:list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:drawSelectorOnTop="false" />

    <TextView
        android:id="@id/android:empty"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="No data">
        </TextView>

</LinearLayout>

tableheader.xml

<?xml version="1.0" encoding="utf-8"?>
<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">
<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/table_header">
    <TableRow>
    <TextView 
        android:text="Name"
        android:id="@+id/team_title">
        </TextView>
    <TextView android:text="P "
        android:gravity="right"
        android:id="@+id/team_played">
    </TextView>
    <TextView android:text="W"
        android:id="@+id/team_won">
    </TextView>
    <TextView android:text="D"
        android:id="@+id/team_drawn">
    </TextView>
    <TextView android:text="L"
        android:id="@+id/team_lost">
    </TextView>
    <TextView android:text="P"
        android:id="@+id/team_points">
    </TextView>
  </TableRow>
  </TableLayout>

    <ListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:drawSelectorOnTop="false" />
   </LinearLayout>

main_tab.xml

<?xml version="1.0" encoding="utf-8"?>
<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"
    >  

    <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/table">
    <TableRow>
        <TextView  
            android:text=""
            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" />
            <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" />
            <TextView  
            android:id="@+id/item_won"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:padding="2dp"
            android:textSize="13dp" />
            <TextView  
            android:id="@+id/item_drawn"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:padding="2dp"
            android:textSize="13dp" />
            <TextView  
            android:id="@+id/item_lost"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:padding="2dp"
            android:textSize="13dp" />
            <TextView  
            android:id="@+id/item_points"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:padding="2dp"
            android:textSize="13dp" />
            </TableRow>
            </TableLayout>

</LinearLayout>

Thanks for the help!!!

dave.c
  • 10,910
  • 5
  • 39
  • 62
julian9876
  • 61
  • 1
  • 8
  • please provide the logcat, so we can know where u getting error – mayank_droid Apr 16 '12 at 10:44
  • Ok.. so there is a long list of errors... but this is the first error that i think is causing all the problems: 04-16 10:52:13.106: E/AndroidRuntime(339): 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' – julian9876 Apr 16 '12 at 10:54
  • is the name of the layout file tableheader.xml or table_header.xml – potter Apr 16 '12 at 10:57
  • well to @mak_just4anything, i have adjusted all the ids so that they are all the same format... the problem with only having one xml fils is that when it creates the listadapter you have to set a layout. So if i put all the heading in that layout, it loops it.. e.g: team P W L D P arsenal 1 1 1 1 1 team P W L D P man utd 1 1 1 1 1 – julian9876 Apr 16 '12 at 11:39
  • if ur problems still not solved then upload all the logcat lines which are red.. – mayank_droid Apr 16 '12 at 11:51
  • ok so i tried something else... i tried just changing the listview id and then include the setContentView(R.layout.table_header); i still get the same error of: – julian9876 Apr 16 '12 at 11:58
  • 04-16 10:52:13.106: E/AndroidRuntime(339): 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' – julian9876 Apr 16 '12 at 11:59
  • @mak_just4anything what do you think??? – julian9876 Apr 16 '12 at 13:18
  • try removing android from android:list, this else i can say.. – mayank_droid Apr 16 '12 at 13:21
  • @mak_just4anything I got the same error: 04-16 14:55:25.407: E/AndroidRuntime(439): 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' – julian9876 Apr 16 '12 at 14:56

1 Answers1

0

first the thing is that you must not change the layout file(SetContentView()) like this and mistake where you doing is that you are declaring id in other files are @+id/list where in that listplaceholder.xml file is @+id/android:list, so naturally it will cause error, so make both ids of same name first. At last, I advice not use two layout xml file for saving the activity you must use only single xml for displaying activity.

mayank_droid
  • 1,015
  • 10
  • 19