开发者

Using multiple layouts with include tag in Android

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开发者_Go百科.layout.main);
TableLayout t = (TableLayout) findViewById(R.id.main_table);

but t always ends up null.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜