3

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
  • In your example the main layout file is called 'main' but you setContentView with 'schedule'. Is there a link ? If not, check whether there is no other id/main_table element in the same layout. Commented Oct 19, 2010 at 3:36
  • Actually was just a typo in my question, sorry! Edited it to reflect what I meant. Commented Oct 19, 2010 at 3:37

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.