tags:

views:

51

answers:

1

I'm trying to create a title bar that is the same throughout my application and have been creating layouts like this for each of my activities:

main.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">
 <include layout="@layout/title_bar_layout" android:id="@+id/title_bar_layout" />
 <include layout="@layout/main_body" android:id="@+id/main_body" />
</LinearLayout>

main_body.xml:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/main_table" android:layout_width="fill_parent"
 android:layout_height="fill_parent" android:stretchColumns="1"
 android:orientation="vertical">
</TableLayout>

my onCreate contains:

setContentView(R.layout.main);
TableLayout t = (TableLayout) findViewById(R.id.main_table);

but t always ends up null.

+2  A: 

Give this a try:

TableLayout t = (TableLayout) findViewById(R.id.main_body);

From this page:

you can use android:id to specify the id of the root view of the included layout; it will also override the id of the included layout if one is defined

Dave
I had actually tried this earlier and didn't realize it was working because something else I did trying to fix it caused a similar error just a bit later, thanks!
powerj1984