4

I want to reuse my tabs like footer for each activities in my application.

I'm using this code

<TabHost
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_above="@android:id/tabs" />

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true" />

        </RelativeLayout>

    </TabHost>

and I want to add components like ListView, Button etc on top of my tabs for each layout. How can I manage this?

BCK
  • 617
  • 2
  • 11
  • 20

1 Answers1

2

I've done something similar by extending a common base activity, in which I've overriden the method setContentView.

abstract public class BaseActivity extends Activity {
    @Override
    public void setContentView(View view) {

        // get master
        LayoutInflater inflater = LayoutInflater.from(this);

        // this is the master view with a container and the footer, you can
        // as well add the header
        RelativeLayout rlMasterView = (RelativeLayout) inflater.inflate(R.layout.master, null);

        rlMasterView.addView(view);

        super.setContentView(rlMasterView);
    }
}

The setContentView creates the footer and attaches it to the view that I'm setting in each activity.

I could as well just use the include tag in each layout.

<include src="footer" />
sebataz
  • 1,025
  • 2
  • 11
  • 35
  • If I want to use the TabHost in my each layout, how can I manage this? For example, my layout contains ListView, Button and the tabs at the bottom. – BCK Dec 29 '11 at 15:40
  • you can use a master template, and after inflating it you can add the sub-activity content view wherever you want – sebataz Dec 30 '11 at 19:37